【问题标题】:Radiobuttons in a radioGroup in a multiple rows多行中的 radioGroup 中的单选按钮
【发布时间】:2015-07-28 16:16:46
【问题描述】:

是否可以创建一个 RadioGroup 来连续保存 3 个单选按钮?我已经在互联网上检查了一个实现,我找到了一个,但它不起作用。问题是我需要以编程方式添加它们,并且它们应该每行分组 3 个。

谁能告诉我如何使用 RadioButtons 填充 radioGroup,以便它们每行对齐 3 个。

谢谢

【问题讨论】:

标签: android android-view android-inflate android-radiogroup android-radiobutton


【解决方案1】:

Radiogroup 继承自 LinearLayout。
因此,将 RadioGroup orientation 属性设置为 "horizontal"

【讨论】:

  • 是的,但是如果水平的所有这些都将在一行中,如何将它们每行放置 3 个。这就是问题
  • 制作几行。我认为这些 RadioGroups 是 ListView 中的项目。
【解决方案2】:

Radio Group 继承自 LinearLayout ViewGroup,因此您可以通过在视图组 android:orientation="horizontal" 上设置方向来实现这一点

  <RadioGroup
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <RadioButton
        android:text="Radio 1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RadioButton
        android:text="Radio 2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RadioButton
        android:text="Radio 3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RadioGroup>

【讨论】:

  • "3 per row" 表示多行。这是如何解决的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-21
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多