【问题标题】:Add dynamically RadioButtons and organised column-wise tabular form动态添加 RadioButtons 和按列组织的表格形式
【发布时间】:2018-03-28 10:04:24
【问题描述】:

我在ConstraintLayout 中有一个RadioGroup。我有一个单选按钮列表(那些来自远程服务器调用)。所以单选按钮的数量不是固定的。有时它可以是 5 个,有时是 10 个或任何大小。我必须按列显示这些单选按钮,如下图所示。

我已经关注this 线程来动态添加单选按钮。我可以水平或垂直显示单选按钮。为了显示水平,我使用了以下代码:

healthCheckRadioGroup.setOrientation(LinearLayout.HORIZONTAL);

for(String healthPlan: healthCheckPlanList){
    RadioButton radioButton = new RadioButton(getContext());
    radioButton.setId(View.generateViewId());
    radioButton.setText(healthPlan);

    healthCheckRadioGroup.addView(radioButton);
}

上述代码的结果是一个单选按钮的水平列表。并且大多数按钮都超出了父布局(我的意思是不可见)

请帮我获取输出。谢谢。

【问题讨论】:

    标签: android radio-button radio-group


    【解决方案1】:

    经过长时间的搜索,我找到了this library,达到了我的要求。我可以在这里设置列数。只需添加这一行:

    healthCheckRadioGroup.setMaxInRow(4);

    剩下的部分代码和以前一样。

    如果有人可以提出更好的解决方案,欢迎您。

    【讨论】:

      猜你喜欢
      • 2019-09-28
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      相关资源
      最近更新 更多