我需要在ImageView的边缘创建一个阿尔法渐变,最好只使用XML来实现。
我需要在ImageView的边缘创建一个阿尔法渐变,最好只使用XML来实现。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#00FFFFFF"
android:endColor="#FFFFFFFF"
android:type="linear" />
</shape>
为了透明:
最初的回答:
android:startColor="@null"
android:startColor="#FF000000"
最初的回答中提到的前两个FF是指颜色的alpha通道,00表示完全透明,而FF则表示不透明。
如果您想要无色透明度,需要编写自定义ImageView。
如果您的背景是静态颜色,则可以使用以下方法进行处理:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/your_image"/>
<item>
<shape android:shape="rectangle">
<gradient android:startColor="#00efefef"
android:endColor="#ffefefef"
android:angle="270"
android:type="linear"/>
</shape>
</item>
</layer-list>