Android 自定义单选按钮图像未填充空间
我有一个定制的单选按钮,背景是9块图案。我使用选择器来确定背景。 我也有一些文字,我想放在背景的图像,但文本是对齐旁边的按钮 这是放射组Android 自定义单选按钮图像未填充空间,android,radio-button,css-selectors,Android,Radio Button,Css Selectors,我有一个定制的单选按钮,背景是9块图案。我使用选择器来确定背景。 我也有一些文字,我想放在背景的图像,但文本是对齐旁边的按钮 这是放射组 <LinearLayout android:id="@+id/segmented" android:layout_width="fill_parent" android:layout_height="50sp" android:gravity="center" android:layout_below="@+id
<LinearLayout
android:id="@+id/segmented"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:gravity="center"
android:layout_below="@+id/header">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/group1"
android:gravity="center">
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="@+id/rbVerzekeringen"
android:text="Verzekeringen"
android:textSize="10sp"
android:button="@drawable/checkbox_theme" />
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="@+id/rbPersoonlijk"
android:text="Persoonlijk"
android:textSize="10sp"
android:button="@drawable/checkbox_theme" />
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="@+id/rbNotities"
android:text="Notities"
android:textSize="10sp"
android:button="@drawable/checkbox_theme" />
</RadioGroup>
</LinearLayout>
这是选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/bt_filter_active" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/bt_filter" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/bt_filter_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/bt_filter" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/bt_filter_active" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/bt_filter" />
<item android:state_checked="false" android:drawable="@drawable/bt_filter" />
<item android:state_checked="true" android:drawable="@drawable/bt_filter_active" />
</selector>
这就是它看起来的样子:
正如你们所知道的,我想要3个上面有文字的大按钮
我该怎么做
编辑:
我将选择器设置为background而不是button,并将按钮设置为null
代码如下所示:
<LinearLayout
android:id="@+id/segmented"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:gravity="center"
android:layout_below="@+id/header">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/group1"
android:gravity="center">
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="40sp"
android:id="@+id/rbVerzekeringen"
android:text="Verzekeringen"
android:textSize="13sp"
android:orientation="vertical"
android:background="@drawable/checkbox_theme"
android:button="@null"
android:gravity="center"/>
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="35sp"
android:id="@+id/rbPersoonlijk"
android:text="Persoonlijk"
android:textSize="35sp"
android:background="@drawable/checkbox_theme"
android:button="@null"
android:gravity="center"/>
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="30sp"
android:id="@+id/rbNotities"
android:text="Notities"
android:textSize="13sp"
android:background="@drawable/checkbox_theme"
android:button="@null"
android:gravity="center"/>
</RadioGroup>
</LinearLayout>
但现在,当我将按钮变大或变小时,其中的文本就会像这样消失(第一幅图像的高度是40 SP,第二幅是35 SP,最后一幅是30 SP):
如何在不剪切背景图像中的文本的情况下使背景图像变小?您是否尝试将可绘制图像设置为android:background而不是按钮 看
编辑:
我不确定,但我认为这取决于9-patch内容区域(底部和右侧边缘线),如果9-patch设置为背景,Android将根据该区域设置填充。内容区域随图像拉伸。你说得对。我做了一个稍微不同的9补丁图片,现在看起来不错。谢谢你的帮助!