我正在编写一个XML选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/image_state2" android:state_pressed="true"/>
<item android:drawable="@drawable/image_state1"/>
</selector>
我只希望state1是透明的,因此将图像视为-是
状态1
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#00000000"
android:startColor="#00000000" />
现在我想让state2遮盖我已经完成的图片。我的问题是,除了阴影渐变以外,我还希望图标显示在中心。我不知道如何通过xml添加它
状态2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#80000000"
android:startColor="#80000000" />
您可以通过将layer-list用于ex来做到这一点:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#80000000"
android:startColor="#80000000" />
</shape>
</item>
<item>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background"
android:tileMode="repeat" android:gravity="center" />
</item>
</layer-list>
将以上内容另存为@ drawable / image_state2。
有关更多信息:调整可绘制图层列表内的位图大小
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句