android RadioButton 图片和文字文字、图片、android、RadioButton

由网友(做一颗冷太阳)分享简介:我正在使用单选按钮创建自定义选项卡主机,工作正常,但现在我需要在顶部显示图标,在图标下方显示文本,Im using a radio button to create a custom tab host, is working fine, but now I need to show the icon on top a...

我正在使用单选按钮创建自定义选项卡主机,工作正常,但现在我需要在顶部显示图标,在图标下方显示文本,

Im using a radio button to create a custom tab host, is working fine, but now I need to show the icon on top and the text underneath the icon,

这就是我现在所拥有的:

this is what I have now:

但这正是我需要的:

这是我的代码:

    <RadioButton
        android:id="@+id/rad_home"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/rad_background"
        android:button="@drawable/home_icon"
        android:gravity="center"
        android:text="Home"
        android:textColor="@drawable/text_background"
        android:textSize="@dimen/rad_text_size" >


    </RadioButton>

    <RadioButton
        android:id="@+id/rad_1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/rad_background"
        android:button="@null"
        android:gravity="center"
        android:text="Menu"
        android:textColor="@drawable/text_background"
        android:textSize="@dimen/rad_text_size" />

    <RadioButton
        android:id="@+id/rad_2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/rad_background"
        android:button="@null"
        android:gravity="center"
        android:text="VIP"
        android:textColor="@drawable/text_background"
        android:textSize="@dimen/rad_text_size" />

    <RadioButton
        android:id="@+id/rad_3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/rad_background"
        android:button="@null"
        android:gravity="center"
        android:text="About"
        android:textColor="@drawable/text_background"
        android:textSize="@dimen/rad_text_size" />

    <RadioButton
        android:id="@+id/rad_4"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/rad_background"
        android:button="@null"
        android:gravity="center"
        android:text="Whats On"
        android:textColor="@drawable/text_background"
        android:textSize="@dimen/rad_text_size" />
</RadioGroup>

所以我将按钮图标设置为:

So im setting the button icon with:

android:button="@null"

android:button="@null"

什么时候是空的

android:button="@drawable/home_icon"

android:button="@drawable/home_icon"

对于图标图像,我应该用它来设置图标吗?如何根据需要组织它?[图标在上,文字在下]

for the icon image, should I use this to set the icon? how to organize it as I need it? [icon on top, text bottom]

我尝试了内部布局,但似乎不喜欢它?

I tried with a layout inside , but doesnt seem to like it?

如何做到这一点?

谢谢!

推荐答案

试试这个:用drawableTop显示图标

Try this: use drawableTop to show the icon

 <RadioButton
    android:id="@+id/rad_home"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="@drawable/rad_background"
    android:button="@null"
    android:drawableTop="@drawable/home_icon"
    android:gravity="center"
    android:text="Home"
    android:textColor="@drawable/text_background"
    android:textSize="@dimen/rad_text_size" >
阅读全文

相关推荐

最新文章