如何使 radioGroup 中 radioButton 的整个区域可点击?
How to make entire area of radioButton within a radioGroup clickable?
我可以点击radioGroup 中的radioButton,"upto" radioButton 之后显示的文本区域,而不是文本区域之后的空白space。有没有办法让它也可以点击?
我想我已经把问题解释清楚了,如果没有请告诉我。˙
详情如下。
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 的 onclicklistener 来调用 radiobutton.toggle。
您可以将 RadioButton 宽度扩展到 match_parent
:
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
然后它将占用与您的 RadioGroup
一样多的宽度,而不是仅仅停留在文本长度上。
为简洁起见发布答案。
添加 LinearLayout 参数并将其添加到 radioGroup.addView(...) 修复它。
LinearLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
radioGroup.addView(radioButton, layoutParams);
我可以点击radioGroup 中的radioButton,"upto" radioButton 之后显示的文本区域,而不是文本区域之后的空白space。有没有办法让它也可以点击?
我想我已经把问题解释清楚了,如果没有请告诉我。˙
详情如下。
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 的 onclicklistener 来调用 radiobutton.toggle。
您可以将 RadioButton 宽度扩展到 match_parent
:
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
然后它将占用与您的 RadioGroup
一样多的宽度,而不是仅仅停留在文本长度上。
为简洁起见发布答案。 添加 LinearLayout 参数并将其添加到 radioGroup.addView(...) 修复它。
LinearLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
radioGroup.addView(radioButton, layoutParams);