0

用例:

如果您要设计多个按钮,并且希望在其中包含不同的图像和背景渐变。

我现在拥有的

ImageButton 的背景如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" >
    <layer-list>
        <item>
            <shape android:shape="rectangle">
                <gradient
                    android:type="linear"
                    android:startColor="@color/green_yellow"
                    android:endColor="@color/green_mantis" />

            </shape>
        </item>
        <item>
            <bitmap
                android:antialias="true"
                android:gravity="center"
                android:src="@drawable/more_button_check_rates_img"/>
        </item>
    </layer-list>
</item>
</selector>

这是可行的,但现在我想要另一个带有其他位图的。

问题 我可以创建三个文件(1 个形状和两个按钮),然后将形状包含到两个按钮中。

像这样的东西:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" >
    <layer-list>
        <include shape="background"> <!-- this line -->
        <item>
            <bitmap
                android:antialias="true"
                android:gravity="center"
                android:src="@drawable/more_button_check_rates_img"/>
        </item>
    </layer-list>
</item>
</selector>
4

1 回答 1

0

是的,您必须为多个背景按钮创建多个 xml,然后在这些按钮上设置该 xml。:)

于 2013-10-17T12:51:53.167 回答