在显示单选按钮定制中心绘制和文字 [英] Display Custom drawable and text in center of radio button
问题描述
我写一个应用程序,我需要在相等的水平空间来绘制两个单选按钮。通过设置实现了我的android:layout_weight =1属性为单选按钮的
I am writing an application where I need to draw two radio button in equal horizontal space. That I achieved by set android:layout_weight="1" property for both of radio button.
现在我需要在中心显示自定义绘制按钮,并需要将文字绘制的里面,这样的:
Now I need to display custom drawable button in centre and need to place text inside of that drawable, like this:
两者的行为在这里画绘和文字是动态的。
Here behaviour of both draw drawable and text is dynamic.
有没有办法在中心实现双方的事情。
Is there any way to achieve both things in centre.
推荐答案
给一个尝试以下code达到所需的输出。
Give a try to the following code to achieve the desired output.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rd_bg"
android:button="@null"
android:gravity="center"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/rd_bg"
android:gravity="center"
android:text="30"/>
</LinearLayout>
</LinearLayout>
下面是code为绘制duration_selector
Below is the code for drawable duration_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:state_focused="true">
<shape android:shape="oval">
<solid android:color="@color/login_bg"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
<item
android:state_checked="false"
android:state_focused="true">
<shape android:shape="oval">
<solid android:color="@color/login_bg"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
<item
android:state_checked="true">
<shape android:shape="oval">
<solid android:color="@color/login_bg"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
<item
android:state_checked="false">
<shape android:shape="oval">
<solid android:color="@android:color/transparent"/>
<stroke android:color="@color/login_bg"
android:width="1dp"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
@色/ login_bg是颜色code,你想用。
@color/login_bg is the color code which you would like to use.
这篇关于在显示单选按钮定制中心绘制和文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!