您好我正在尝试使用shape.xml
在顶部获得渐变之类的阴影从图像中按下线性布局中的按钮,我想在布局顶部给出渐变。
我做的如下,但它没有成功
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#f0f0f0" />
<solid android:color="#f0f0f0" />
</shape>
</item>
<item android:top="1dp">
<shape
android:shape="line">
<gradient
android:angle="90"
android:type="linear"
android:startColor="#FFFFFF"
android:endColor="#000000" />
</shape>
</item>
</layer-list>
答案 0 :(得分:10)
无需使用图层列表,您可以通过Gradient
执行此操作。试试这个流动的代码 - &gt;
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#b4909090" android:endColor="#b4fafafa" android:angle="90"/>
</shape>
根据需要更改startColor
和endColor
。结果是 - &gt;
答案 1 :(得分:2)
只需使用:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="linear"
android:centerX="78%"
android:startColor="#FFf7f7f7"
android:centerColor="#FFC0C0C0"
android:endColor="#FFbebebe"
android:angle="90"/>
</shape>