简体   繁体   中英

How to change direction of android elevation shadow?

I have FrameLayout with android:elevation="4dp". Shadow of this elevation directed down. I want change direction of shadow to up.

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

I consider this method is the best solution: Android Bottom Navigation Bar with drop shadow Thanks, Alexander Bilchuk.

Solution:

You can draw your own shadow just above the view using simple View and its background:

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

drawable/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>

Also, there are no compatibility issues if use this approach.

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

视图阴影可以被翻译,或通过改变如在此详述的视图的轮廓提供者在x和y方向上,更经缩放

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM