gpt4 book ai didi

android - 如何在单选按钮的中心绘制图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:17 25 4
gpt4 key购买 nike

我正在查看 http://bakhtiyor.com/2009/10/iphonish-tabs/ 中发布的示例,实际上他们在这里放置了单选按钮作为 Tabview 的替代品。

但问题是,我无法将图像设置到中心。它总是向左对齐。

这是截图。我希望我的 View 看起来像这样,但我希望图像居中。 enter image description here

这是我的布局 XML 文件的样子

    <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="20dip"/>

<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/allcontacts"
android:gravity="center"
android:id="@+id/contactgroup">


<RadioButton android:id="@+id/allcontacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:background="@drawable/button_radio"/>


<RadioButton
android:id="@+id/categories"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_radio"
android:orientation="vertical"
android:layout_gravity="center|right"/>

<RadioButton android:id="@+id/favourites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:background="@drawable/button_radio"/>

</RadioGroup>

<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" android:visibility="gone" />
</LinearLayout>
</TabHost>

请多多指教

使用默认选项卡小部件后的更新图像 enter image description here

是否可以在默认选项卡 View 中像上面的单选按钮一样自定义?

最佳答案

实际上并没有使图像居中,但你可以让它看起来那样......你可以修改图像以在左侧留有空白并在图像右侧立即切掉。

编辑

我不知道你是否看过这些,但你让我很好奇,所以我继续寻找并找到了几个链接,这些链接可能有助于实现底部标签的最终目标:

Niko's Blog

SO Question Answer

Another SO Question Answer

祝你好运!

编辑2

好的,找到了。您将必须从 RadioButton 扩展一个新类并覆盖 onDraw(),然后创建一个您需要放入 res/values 的 attrs.xml 文件,以便代码可以获取平台定义的属性。

Specific code here

关于android - 如何在单选按钮的中心绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10468160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com