单选按钮多行 [英] radio button multiple rows
问题描述
我要显示相同的无线组6单选按钮。但是,所有的6单选按钮保持在同一直线上,并熄灭屏幕。如何在两排(每3个单选按钮)显示它们?
我尝试了一切可能为我(我是新至Android)。
I want to display 6 radio buttons of same radio group. But all the 6 radio buttons remain on same line and goes off the screen. How to display them in two rows (3 radio buttons each)? I tried everything possible for me (I am new to android).
推荐答案
从各地搜索,似乎没有被这样做的一种方式,因为RadioGroup中使用的LinearLayout,它不换行。由于单选按钮必须是直接的孩子单选组,你不能子布局添加到无线电集团。
From searching around, there doesn't appear to be a way of doing it, as RadioGroup uses LinearLayout, which does not wrap. As radio buttons must be direct children to the radio group, you can't add sub-layouts to radio group.
这意味着你必须手动实现这一布局行为。两种可能的选项是:
This means you will have to implement this layout behaviour manually. Two possible options are:
- 创建RadioGroup中的副本来扩展不同的布局,或者至少允许你动态地控制它。
- 实施自己的自定义布局,以取代
RadioGroup中
扩展您所选择的布局,并实施OnClickListener
。有一个很好的例子,<一个href=\"http://stackoverflow.com/questions/2381560/how-to-group-a-3x3-grid-of-radio-buttons\">here.
- Create a copy of RadioGroup to extend a different layout, or at least allow you control it dynamically.
- Implement your own custom layout to replace
RadioGroup
that extends a layout of your choice, and implementsOnClickListener
. There's a good example here.
这篇关于单选按钮多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!