代码之家  ›  专栏  ›  技术社区  ›  A23149577

布局的Android阴影颜色

  •  0
  • A23149577  · 技术社区  · 10 年前

    我开发了一个 listView 我的应用程序。我的UI很简单 flat UI ,这是一张快照:

    enter image description here

    当我在互联网上搜索更好的界面时,我发现了这个例子: enter image description here

    如您在本示例中所见,背景色在底部有阴影。有没有一种方法可以像这样为布局背景上色?提前感谢。

    3 回复  |  直到 10 年前
        1
  •  2
  •   reVerse    10 年前

    为了达到阴影效果,我想最好使用 layer-list 对于两个项目,一个是纯色,第二个项目是从透明到具有alpha值的黑色的渐变。

    这是它的样子(需要放在 res/drawable/ ):

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#ff33b5e5" />
            </shape>
        </item>
        <item>
            <shape android:shape="rectangle">
                <gradient
                    android:angle="-90"
                    android:endColor="#90000000"
                    android:startColor="@android:color/transparent" />
            </shape>
        </item>
    </layer-list>
    

    这样做,你就不需要一直“搜索”纯色中较深的颜色。

    输出将如下所示:

    enter image description here

        2
  •  2
  •   Jigar    10 年前

    创建一个XML文件,并在Res->中将其命名为“gradient_effect”;可绘制文件夹,并将以下代码放入其中

     <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
          android:startColor="#a0a0a0"
          android:endColor="#f5f5f5"
          android:angle="0"
    
          /> 
    

    现在,将此文件用作任何布局中的背景,如下图所示

    android:Background= "@Drawable/gradient_effect"
    

    将上面的行设置为xml文件中任何视图或布局的属性

        3
  •  0
  •   Hadi Note    7 年前

    这也有帮助!

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:angle="90"
                android:endColor="#A2000000"
                android:startColor="@android:color/transparent" />
        </shape>
    </item>