【发布时间】:2016-04-06 02:06:09
【问题描述】:
我正在尝试将我的自定义 RadioButton 设为如下所示:
所以我做了自定义可绘制对象来响应 RadioButton 状态并将其用作背景。没关系。
问题是我无法将通过android:button 属性设置的图像居中。
这是我尝试在布局中使用它的方式。
<RadioGroup
android:id="@+id/presenter_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp"
android:gravity="center"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/cluster_centered"
android:gravity="center"
android:padding="8dp"
android:background="@drawable/presenter_radiobutton_left"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:background="@drawable/presenter_radiobutton_right"
android:button="@drawable/fire"
/>
</RadioGroup>
有了这个,我得到了这个结果:
我已经尝试定义一个将重力设置为中心的可绘制对象,但没有任何改变。这是自定义可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/cluster" android:gravity="center"/>
</item>
</selector>
那么,我怎样才能使按钮图像居中?
PS:我不能将每种按钮都设置为背景,因为它会在未来是动态的,所以唯一可以在背景中的是蓝色形状。
【问题讨论】: