据我所知,单选按钮可以完成,但不像其他 EditText 或 TextView 那样。
试试这个代码..
<RadioGroup android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:checkedButton="@+id/first">
<RadioButton android:id="@+id/first"
android:width="50dp"
android:height="50dp"
android:button="@drawable/button_radio"/>
<RadioButton android:id="@+id/second"
android:width="50dp"
android:height="50dp"
android:button="@drawable/button_radio"/>
<RadioButton android:id="@+id/third"
android:width="50dp"
android:height="50dp"
android:button="@drawable/button_radio"/>
<RadioButton android:id="@+id/fourth"
android:width="50dp"
android:height="50dp"
android:button="@drawable/button_radio"/>
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
还要看看这个示例..这会对您有很大帮助..
小智 5
如果您正在使用单选按钮,那么通常它需要android-sdk的图像资源,例如./ Android的SDK-MacOSX的/平台/机器人-10 /数据/ RES /抽拉-HDPI
如果你想自定义它,然后从这个文件夹中获取资源并调整大小(我得到它的大小为34 x 48,大小调整为19 x 24)然后你可以使用它像这样:
这是我的radio_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_radio_on" android:state_checked="true" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_radio_off" android:state_checked="false" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_radio_on_pressed" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_radio_off_pressed" android:state_checked="false" android:state_pressed="true"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我的main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="30dp"
android:checkedButton="@+id/first"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/first"
android:button="@drawable/radio_button"
android:height="20dp"
android:width="20dp" />
<RadioButton
android:id="@+id/second"
android:button="@drawable/radio_button"
android:height="20dp"
android:width="20dp" />
<RadioButton
android:id="@+id/third"
android:button="@drawable/radio_button"
android:height="20dp"
android:width="20dp" />
<RadioButton
android:id="@+id/fourth"
android:button="@drawable/radio_button"
android:height="20dp"
android:width="20dp" />
</RadioGroup>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
由于声誉较低,我无法在此处上传图片,因此我提供了资源和输出图像的链接.
https://www.dropbox.com/sh/7518zf3onh4su0z/fO7CP7o1EY
| 归档时间: |
|
| 查看次数: |
26375 次 |
| 最近记录: |