35

我有带有 android:elevation="4dp" 的 FrameLayout。这个高地的阴影指向下方。我想改变阴影的方向向上。

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:elevation="10dp"
    android:layout_marginBottom="100dp"
    android:background="@color/ColorPrimary"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">
</FrameLayout>
4

3 回答 3

26

我认为这种方法是最好的解决方案:带有阴影的 Android 底部导航栏谢谢 Alexander Bilchuk。

解决方案:

您可以使用简单的 View 及其背景在视图上方绘制自己的阴影:

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

可绘制/shadow.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#1F000000"
        android:endColor="@android:color/transparent"
        android:angle="90" />
</shape>

此外,如果使用这种方法,也不存在兼容性问题。

于 2018-04-04T16:52:46.020 回答
4

视图投影可以通过更改视图的轮廓提供程序在 x 和 y 方向进行平移或缩放,如本文所述

于 2019-04-03T13:39:58.980 回答
0

As far as I'm concerned, you don't change the shadow by yourself. In Androids Material Design, the shadow is automatically determined by the amount you elevate a element.

According to this question https://graphicdesign.stackexchange.com/questions/80644/where-are-the-light-sources-located-in-material-design the light source is

45 degrees altitude and 90 degrees angle

You really shouldn't use different shadows as it will destroy the overall consistency of material design. Then only thing you should do is elevate your elements. Maybe you should re-read the Material Design Guidlines: https://material.io/guidelines/material-design/environment.html#environment-light-shadow

于 2017-04-04T03:58:06.103 回答