按钮上方带有文本的单选按钮 [英] Radiobutton with text above button
问题描述
我是 android 新手,我需要在我的活动中添加单选按钮,但我需要将文本放在项目符号按钮的顶部.
请帮忙.我发现了以下内容,虽然我不明白 @drawable/main_selector 和 @style/TabStyle.
阅读有关选择器的更多信息.
获取文本顶部的示例:
<单选按钮android:text="顶部的文字"机器人:按钮=@null"机器人:背景=#f00"android:layout_weight="1"/><单选按钮android:text="顶部的文字"机器人:按钮=@null"机器人:背景=#0f0"android:layout_weight="1"/></RadioGroup>
将给出以下结果:
如果您希望文本显示在按钮上方,您可以使用以下 xml:
<单选按钮android:text="顶部的文字"机器人:按钮=@null"android:drawableBottom="@android:drawable/btn_radio"机器人:重力=中心"android:layout_weight="1"/><单选按钮android:text="顶部的文字"机器人:按钮=@null"android:drawableBottom="@android:drawable/btn_radio"机器人:重力=中心"android:layout_weight="1"/></RadioGroup>
这将给出以下结果:
I am new to android and I need to add radio buttons on my activity, but i need to place the text on the to of the bullet button.
Any help please. I found the following, though I dont understand what the @drawable/main_selector and @style/TabStyle.
Can anyone give me a 101 guide.
UPDATE
I used the following according to some suggestion but didnt work:
<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>
UPDATE 2
I got my solution from Warpzit, but befor i mark the question as answered, can someone help me on the alignment issue below. I will have 5 radio buttons in a row where some of them will have longer text split in 2 lines. when the text fit on the screen, because of landscape, or on tablets then all text should be in one line:
UPDATE 3
... depending on the screen size the text can split into different number of lines. It wont be always standard
The @style/TabStyle
is simply a style that is applied, you can ignore that. The @drawable/main_selector
is a graphic that is toggled depending on the situation. You can read more about selectors here.
Example to get text on top:
<?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>
Will give following result:
If you want the Text to appear above the button you can use following 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>
This will give following result:
这篇关于按钮上方带有文本的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!