Android 有没有办法让无线电组水平布置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11443492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to have a radio group be laid out horizontally?
提问by Ted pottel
I have 2 radio buttons inside a radio group. Right now they are lined up vertically. I tried putting them in a horizontal container, but it did not worck.
我在一个单选组中有 2 个单选按钮。现在它们垂直排列。我试着把它们放在一个水平的容器里,但没有用。
Is there a way to get a radio group of buttons to line up horizontaly?
有没有办法让一组按钮水平排列?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioChats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chats"
android:checked="true" />
<RadioButton
android:id="@+id/radioPlayers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Players"
android:checked="true" />
</RadioGroup>
<Button android:text="Home"
android:id="@+id/buthome"
android:paddingTop="-15dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:text="Players"
android:id="@+id/butplayers"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/viewActivePlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TedP"
android:layout_gravity="right"
android:textColor="#fffff109"
android:textSize="26dip" />
回答by azgolfer
Add android:orientation="horizontal"
to RadioGroup
tag:
添加android:orientation="horizontal"
到RadioGroup
标签:
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation='horizontal'>
回答by arlomedia
You can also set this programmatically:
您还可以以编程方式设置:
myRadioGroup.setOrientation(LinearLayout.HORIZONTAL);