Android XML: Drop shadow cut off Android XML: Drop shadow cut off android android

Android XML: Drop shadow cut off


In your relative layout tag, use padding instead of margin and add the attribute android:clipToPadding="false" to avoid the shadows being cut.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:padding="@dimen/activityMargin"        android:clipToPadding="false">


Problem is that shadows are cut by bounds of view or view group. To tackle this issue you have to use:

android:clipChildren

Defines whether a child is limited to draw inside of its bounds or not.

android:clipToPadding

Defines whether the ViewGroup will clip its children and resize (but not clip) any EdgeEffect to its padding, if padding is not zero.

Problem is that you have to set this to many views in xml if you want to render shadow. I resolved this issue on level of themes.xml. In my top level theme I just set:

<item name="android:clipChildren">false</item><item name="android:clipToPadding">false</item>

Then, if there is space on screen, shadow is rendered. I hope it won't break something else.

EDIT: It breaks some vies. For example CameraPreview will set black background to whole screen.