您好,我正在尝试使用 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>
最佳答案
无需使用 Layer-list ,您可以通过 Gradient
来完成。试试这个流畅的代码 ->
<?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
。结果是 ->
关于Android:使用 shape.xml 显示像阴影一样的渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39587415/