Rak*_*sha 3 android android-layout android-xml android-view
更改RadioButton的background属性时遇到一些问题
首先,我想在每个单选按钮下创建一个单选按钮组中的三个行
这是下面的代码
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@android:color/black"
android:orientation="vertical" >
<RadioButton
android:id="@+id/radioBtnFirst"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/custom_radiogroup_divider"
android:text="Answer 1"/>
<RadioButton
android:id="@+id/radioBtnTwo"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/custom_radiogroup_divider"
android:text="Answer 2"/>
<RadioButton
android:id="@+id/radioBtnThree"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/custom_radiogroup_divider"
android:text="Answer 3"/>
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
现在在可绘制文件夹中,custom_radiogroup_divider.xml是
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<stroke
android:width="0.3dp"
android:color="@android:color/black" />
</shape>
Run Code Online (Sandbox Code Playgroud)
但是现在的问题是当我使用背景属性时
单选按钮看起来像文本与单选按钮重叠
您必须通过Java代码设置单选按钮的背景:
radioBtnFirst.setButtonDrawable(R.drawable.custom_radiogroup_divider);
Run Code Online (Sandbox Code Playgroud)
它也可以使用复选框;)
| 归档时间: |
|
| 查看次数: |
4884 次 |
| 最近记录: |