I've been playing around with shadows on Lollipop for a bit and this is what I've found:
- It appears that a parent
ViewGroup
's bounds cutoff the shadow of its children for some reason; and
- shadows set with
android:elevation
are cutoff by the View
's bounds, not the bounds extended through the margin;
- the right way to get a child view to show shadow is to set padding on the parent and set
android:clipToPadding="false"
on that parent.
Here's my suggestion to you based on what I know:
- Set your top-level
RelativeLayout
to have padding equal to the margins you've set on the relative layout that you want to show shadow;
- set
android:clipToPadding="false"
on the same RelativeLayout
;
- Remove the margin from the
RelativeLayout
that also has elevation set;
- [EDIT] you may also need to set a non-transparent background color on the child layout that needs elevation.
At the end of the day, your top-level relative layout should look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/block"
android:gravity="center"
android:layout_gravity="center"
android:background="@color/lightgray"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:clipToPadding="false"
>
The interior relative layout should look like this:
<RelativeLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:background="[some non-transparent color]"
android:elevation="30dp"
>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…