当我开发一个应用程序并且需要单选按钮时,我决定创建一个 RadioGroup
在其中,我创建了 3 RadioButton
s 和我想将它们相应地定位到左侧、中间和右侧。
我输入android:orientation:"horizontal"
在RadioGroup
我已经放置了 android:layout_gravity="left
RadioButton
的右侧或中心在 RadioGroup 内创建的,但它只是将按钮彼此相邻放置并左对齐,并且使文本稍微扭曲。
如果我申请 android:gravity="left"
也会发生同样的事情到按钮。
我不知道如何将第一个按钮对齐左侧,第二个按钮对齐中间,第三个按钮对齐右侧。
谢谢!
最佳答案
在你的布局中尝试一下:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:orientation="horizontal">
<RadioButton
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="1"/>
<RadioButton
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="2"/>
<RadioButton
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="3"/>
</RadioGroup>
关于Android RadioGroup 按钮重力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26961036/