【问题标题】:Transparent Shadow View透明阴影视图
【发布时间】:2015-11-12 01:26:27
【问题描述】:

我正在尝试像在 google play 应用中那样实现透明阴影。 当您向下滚动时,瓷砖位于阴影后面,但您可以看到它们将其扔掉。在此处查看示例图片:

我创建了一个视图,我可以通过

添加到布局中
<include layout="@layout/toolbar_shadow" />

toolbar_shadow.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="@drawable/shadow"
        />
</LinearLayout>

shadow.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="@android:color/transparent"
        android:centerColor="#33333333"
        android:endColor="#aa666666"


        android:angle="90" />
</shape>

我得到的是一个不透明的阴影。当瓷砖在其后面移动时,它会被白色/灰色* 颜色覆盖。

*endColor="#aa666666" 来自 shadow.xml

有人可以帮我吗?

【问题讨论】:

  • 你能贴出包含阴影的整个布局文件吗?

标签: android xml view transparency shadow


【解决方案1】:

试试这个,但根据需要更改渐变颜色

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

或只是将工具栏放入appbarlayout

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@null"
        android:fitsSystemWindows="true"
        app:elevation="3dp">

            <include layout="@layout/toolbar"/>

    </android.support.design.widget.AppBarLayout>

【讨论】:

    【解决方案2】:

    您不能使用这种方式添加透明阴影。因为您的阴影区域在您的栏内,并且 android 在第一个活动中不允许透明背景。一句话,您应该在顶部栏下方的列表布局顶部添加阴影。希望对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2012-07-17
      相关资源
      最近更新 更多