【问题标题】:How to make entire area of radioButton within a radioGroup clickable?如何使radioGroup内的radioButton的整个区域可点击?
【发布时间】:2015-07-03 06:55:47
【问题描述】:

我可以点击radioGroup中的radioButton,“upto”显示在radioButton之后的文本区域,但不能在文本区域之后的空白处。有没有办法让它也可以点击?

我想我已经把问题解释清楚了,如果没有请告诉我。˙

以下是详细信息。

styles.xml

<style name="RBStyle" parent="@android:style/Widget.CompoundButton.RadioButton">
    <item name="android:drawable">@drawable/button_background</item>

    <item name="android:paddingLeft">4dp</item>
</style>

rb_layout.xml

<RadioButton style="@style/RBStyle" />

示例代码

RadioButton radioButton = (RadioButton) layoutInflater.inflate(
            buttonResource, null);

radioButton.setText(buttonName);
radioButton.setId(buttonId);

【问题讨论】:

  • 你想让radioGroup可以点击吗??
  • 我试过了,它不起作用 android:clickable="true"
  • 您可以让您的 radioGroup 视图的父级可点击。
  • @Vid - 这是我试过的 还是不行

标签: android android-radiogroup android-radiobutton


【解决方案1】:

为简洁起见发布答案。 添加 LinearLayout 参数并将其添加到 radioGroup.addView(...) 修复它。

LinearLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
radioGroup.addView(radioButton, layoutParams);

【讨论】:

    【解决方案2】:

    你还需要设置 RadioGroup 的 onclicklistener 来调用 radiobutton.toggle。

    【讨论】:

    • 我没有得到你的答案,这与我面临的问题有什么关系?你能解释一下吗?
    【解决方案3】:

    您可以将 RadioButton 的宽度扩展到match_parent

    <RadioButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    

    然后它将占用与您的 RadioGroup 一样多的宽度,而不仅仅是文本长度。

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 2020-12-10
      相关资源
      最近更新 更多