Android:使用 shape.xml 显示像阴影一样的渐变

标签 android xml gradient android-drawable

您好,我正在尝试使用 shape.xml 仅在顶部获得类似渐变的阴影

enter image description here

从图像中我将按钮包裹在线性布局中,我想在布局顶部提供渐变。

我正在做下面的事情,但没有成功

<?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>

根据需要更改 startColorendColor。结果是 ->

Image For Shadow

关于Android:使用 shape.xml 显示像阴影一样的渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39587415/

相关文章:

python - Theano是否为BPTT做自动展开?

Delphi TDBGrid 当样式为gdsGradient时如何更改选定的颜色

Java switch 语句绕过所有情况,甚至默认情况

android - 我如何检查我的安卓手机是否丢失了 GPS 信号?

xml - 免费的 XML 格式化工具

xml - 如何使用 Scala 创建 xhtml 查询字符串?

c# - 如何从 XmlDocument 中删除空格

html - 在背景图像的底部创建静态淡入淡出

android - 谷歌 6 月 17 日 Firebase SDK 更新后,Ionic Cordova 应用程序停止编译

java - android sql-query 问题..."no such column"?