0
我在写一个应用程序,我需要在相同的水平空间中绘制两个单选按钮。我通过设置android:layout_weight =“1”这两个单选按钮来实现属性。显示自定义绘图和单选按钮中心的文本
现在我需要在中心显示自定义绘制按钮,需要放置文本绘制的里面,是这样的:两个
以下行为画绘制和文字是动态的。
有什么办法可以在中心实现这两件事。
我在写一个应用程序,我需要在相同的水平空间中绘制两个单选按钮。我通过设置android:layout_weight =“1”这两个单选按钮来实现属性。显示自定义绘图和单选按钮中心的文本
现在我需要在中心显示自定义绘制按钮,需要放置文本绘制的里面,是这样的:两个
以下行为画绘制和文字是动态的。
有什么办法可以在中心实现这两件事。
试试下面的代码来实现所需的输出。
<?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>
下面是绘制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是颜色代码,你想使用。
嗨..感谢您的回答。但是因为我需要将按钮放在相同的水平空间中。因此,然后bg图像“duration_selector”得到拉伸和文本在左边对齐。任何其他建议! – CoDe 2014-11-03 08:42:03
@Shubh您可以查看解决方案http://stackoverflow.com/a/19163987/1839336。它可能会帮助你 – GrIsHu 2014-11-03 08:59:43
@ Shubh请检查已编辑的答案 – miteshpithadiya 2014-11-03 09:02:59