来自xml选择器的填充图像 [英] padding image from xml selector
问题描述
我正在尝试将主菜单的按钮背景图像填充(我在使用用于不同状态的选择器),以这种方式进行(buttoninicio_custom.xml):
I'm trying to padd my button background image of my main menu (I'm using a selector for the different states), doing it on this way (buttoninicio_custom.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/botoninicial_pressed"
android:state_pressed="true">
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</item>
<item android:drawable="@drawable/botoninicial_pressed"
android:state_focused="true">
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</item>
<item android:drawable="@drawable/botoninicial">
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</item>
</selector>
..但是填充无效.我应该怎么解决这个问题?
..but the padding has no effect. What I should do to solve this problem??
我已经在每个"item"标签内部使用了"bitmap"标签,并在其中添加了填充,但是它仍然在做任何事情!!!
I already used "bitmap" tag inside each "item" tag with the padding inside, but it's still doing anything!!!
我的主按钮看起来像这样:
My main button looks this way:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/button2"
android:layout_width="180dp"
android:layout_height="50dp"
android:layout_marginBottom="15dp"
android:textSize="16sp"
android:textColor="#FFFFFF"
android:background="@drawable/buttoninicio_custom"
android:text="@string/idmMENU2" />
</LinearLayout>
因为如果我在"button"标签内设置了android:padding,它将填充文本而不是背景图像...问题是当我按下主按钮时:我的图像背景正确更改,但是新图像出现剪裁."
"Because if I set android:padding inside the "button" tag, it pads me the text not the background image... The problem it's that when I pressed the main button: My image background change correctly but the new image appear cut."
推荐答案
将其包装在layer-list
中:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="1dp">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- your original selector content -->
</selector>
</item>
</layer-list>
这篇关于来自xml选择器的填充图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!