我已经在我的应用程序上安装了一个带有三个单选按钮的无线电组,但是我希望文本在它上方,就像复选框一样.我可以像这样引用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>
Run Code Online (Sandbox Code Playgroud)
因为当我运行应用程序时,三个单选按钮显示没有任何文本.或者有更简单的方法吗?
Gak*_*ket 18
老问题,但也许我的答案会帮助别人.
为所有按钮添加标题的方法之一是简单地TextView在内部使用RadioGroup.
当然,您可以为每个单选按钮设置文本.您应该使用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>
Run Code Online (Sandbox Code Playgroud)