Yia*_*nos 12 android radio-button
我是Android的新手,我需要在我的活动上添加单选按钮,但我需要将文本放在项目符号按钮上.
请帮忙.我找到了以下内容,虽然我不明白@ drawable/main_selector和@ style/TabStyle是什么.
任何人都可以给我一个101指南.
UPDATE
我根据一些建议使用了以下内容,但没有奏效:
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:text="something that is on top"
android:id="@+id/toggle_tab_left"
android:button="?android:attr/listChoiceIndicatorSingle"
style="@null"/>
<RadioButton
android:button="?android:attr/listChoiceIndicatorSingle"
android:text="something that is on top"
android:id="@+id/toggle_tab_right"
style="@null"/>
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
更新2
我从Warpzit得到了我的解决方案,但是因为我将问题标记为已回答,有人可以帮我解决下面的对齐问题.我将连续有5个单选按钮,其中一些将有更长的文本分成2行.当文本适合屏幕,因为横向或平板电脑,那么所有文本应该在一行中:

更新3
...根据屏幕大小,文本可以分成不同数量的行.它永远不会是标准的

War*_*zit 29
这@style/TabStyle只是一种应用的风格,你可以忽略它.这@drawable/main_selector是一个根据情况切换的图形.你可以阅读更多关于选择这里.
例如让文字在上面:
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:text="Text on top"
android:button="@null"
android:background="#f00"
android:layout_weight="1"/>
<RadioButton
android:text="Text on top"
android:button="@null"
android:background="#0f0"
android:layout_weight="1"/>
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
将给出以下结果:

如果您希望文本显示在按钮上方,您可以使用以下xml:
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:text="Text on top"
android:button="@null"
android:drawableBottom="@android:drawable/btn_radio"
android:gravity="center"
android:layout_weight="1"/>
<RadioButton
android:text="Text on top"
android:button="@null"
android:drawableBottom="@android:drawable/btn_radio"
android:gravity="center"
android:layout_weight="1"/>
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
这将得到以下结果:

ser*_*1pt 22
为了补充Warpzit伟大的答案,你应该使用android:gravity="center_horizontal|bottom"和android:layout_height="match_parent"操作按钮,将它们对齐.
此外,无需从AOSP复制单选按钮drawables,使用?android:attr/listChoiceIndicatorSingle.

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/radioGroup1"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_horizontal|bottom"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_horizontal|bottom"
android:text="RadioButton dsfsdfsdfsdfsdf" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_horizontal|bottom"
android:text="RadioButton fdsfsd fdsfsdf fsfsdfs" />
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15270 次 |
| 最近记录: |