Android How To Create Gradient Shadow On Left And Right Of View?
I cannot use Lollipop elevation property because I need to target devices from API 18. I need to place a shadow on the right and left side of a view. This is what I tried so far :
Solution 1:
You can try using a gradient
contained within a rectangle, which you can size: example below is a shadow I used for Navigation Drawer. You can modify this to fit your needs.
<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:startColor="#111"android:endColor="#00000000"></gradient><sizeandroid:height="@dimen/activity_vertical_margin"android:width="5dp"></size></shape>
Alternitively, you can use a CardView from v7 CardView support library, which supports Android api 7+.
Solution 2:
You need to create your own drawable for it.
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:angle="270"android:endColor="@android:color/white"android:startColor="@color/black_38"></gradient><sizeandroid:height="4dp"></size></shape>
And then for example with help of relative layout to align to any side of your layout. For me it's bottom shadow of custom app bar.
...
<View
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:background="@drawable/app_bar_shadow"
android:layout_height="4dp"/> // height of your shadow
Post a Comment for "Android How To Create Gradient Shadow On Left And Right Of View?"