I have implemented a NavigationDrawer
in my application. I would like to know how I can add a vertical shadow effect which is below the main Fragment, similar to the picture below.
I have one image on my drawable with the shadow image. It's called "drawer_shadow.9" but I don't know how I can implement this inside my NavigationDrawer
.
(Drawer on right side) Activity layout:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
...
</LinearLayout>
<LinearLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:orientation="horizontal">
<View
android:layout_width="20dp"
android:layout_height="match_parent"
android:background="@drawable/drawer_shadow"
android:paddingEnd="0dp"
android:paddingLeft="-20dp"
android:paddingRight="0dp"
android:paddingStart="-20dp" />
<fragment
android:id="@+id/fragment_drawer"
android:name="com.....HomeDrawer"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
tools:layout="@layout/drawer_home" />
</LinearLayout></android.support.v4.widget.DrawerLayout>
draver shadow:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#00FFFFFF"
android:endColor="#f2e9e9e9"
android:type="linear" />
<size
android:height="@dimen/activity_vertical_margin"
android:width="5dp">
</size>
</shape>
effect:
You will need to use a drawable for the shadow. Use the setDrawerShadow
method on the navigationDrawer object. For example:
navigationDrawer.setDrawerShadow(R.drawable.someDrawable, GravityCompat.START);
Link to the official document: setDrawerShadow
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With