Android ring shape for radio button(单选按钮的Android环形)
问题描述
我需要为我的单选按钮创建 2 个环形:
I need to create 2 ring shapes for my radio buttons:
- 白色圆圈
- 白色圆圈内有另一个不同颜色的圆圈
我没有太多关于如何做到这一点的线索.到目前为止我尝试了什么:
I dont have much clue on how to do this. What I tried so far:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false"><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring">
<android:solid android:color="@color/white" />
<android:size android:height="10dp" android:width="10dp" />
<corners android:radius="10dp" />
</shape></item>
</selector>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/radio_shape_unchecked"
android:checked="false"
android:text="Persoana fizica" />
http://i.stack.imgur.com/mltby.png
推荐答案
这里有一些代码给你..你可以做这样的事情.如果您有任何问题,那么我可以将整个项目邮寄给您.希望这对您和其他人有所帮助.!!
Here is some code for you..You can do something like this. If you have any problem then I can mail you whole project..Hope this helps you and others. !!
res/drawable/red_ring.xml
res/drawable/red_ring.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="3"
android:shape="ring"
android:thickness="10dp"
android:useLevel="false" >
<solid android:color="#FF0000" />
<size
android:height="30dp"
android:width="30dp" />
</shape>
res/drawable/blue_ring.xml
res/drawable/blue_ring.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="3"
android:shape="ring"
android:thickness="5dp"
android:useLevel="false" >
<solid android:color="#0000FF" />
<size
android:height="20dp"
android:width="20dp" />
</shape>
res/drawable/layer.xml
res/drawable/layer.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/red_ring"/>
<item android:drawable="@drawable/blue_ring"/>
</layer-list>
res/drawable/selector_radio.xml
res/drawable/selector_radio.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="@drawable/layer"></item>
<item android:drawable="@drawable/blue_ring"></item>
</selector>
res/layout/activity_main.xml
res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:gravity="center" >
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:button="@drawable/selector_radio"
android:paddingLeft="30dp"
android:text="Radio 1" />
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:button="@drawable/selector_radio"
android:paddingLeft="30dp"
android:text="Radio 2" />
</RadioGroup>
</RelativeLayout>
截图:
这篇关于单选按钮的Android环形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:单选按钮的Android环形


- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01