android – 一个radiogroup可以显示标题/标题吗?

我在我的应用程序上安装了一个带有三个单选按钮的无线电组,但是我希望文本在它上方,就像复选框一样.我可以像这样引用strings.xml文件吗?
<RadioGroup
        android:id="@+id/set_radiogroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/between_games_timer"
        android:orientation="vertical"
        android:text="@string/sets_radio_group" >

        <RadioButton
            android:id="@+id/one_set"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            </RadioButton>
        <RadioButton
            android:id="@+id/two_sets"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            </RadioButton>
        <RadioButton
            android:id="@+id/three_sets"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            </RadioButton>            
    </RadioGroup>

因为当我运行应用程序时,三个单选按钮显示没有任何文本.或者有更简单的方法吗?

解决方法

老问题,但也许我的答案会帮助某人.

为所有按钮添加标题方法之一是简单地在RadioGroup中使用TextView.

当然,您可以为每个单选按钮设置文本.
您应该使用android:text属性为每个按钮设置文本.我在下面的示例中使用了常用字符串,但您最好将字符串提取到Strings.xml中

这是一个例子:

<RadioGroup
    android:id="@+id/set_radiogroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <TextView
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Choose one of three types:"
        />

    <RadioButton
        android:id="@+id/onse_set"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type one"
        />
    <RadioButton
        android:id="@+id/two_sets"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type two"
        />
    <RadioButton
        android:id="@+id/three_sets"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type three"
        />
</RadioGroup>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...