2

I am trying to remove the Drawer shadow when navigation view opens. As suggested in many forums, i have used the below code to remove drawer shadow. But it seems to have no impact.Kindly help me find out where i am going wrong. I am actually trying to achieve the same effect, but when the drawer opens, there seems to be a line/shadow like effect at the end of the drawer.It doesnt look the same as the one in the link. Below is the screenshot of my app. As you can see, there seem to be a line/shadow like effect at the end of the navigation drawer. How can i remove it. I have highlighted the issue in red. my image

Moving and resizing DrawerLayout's content on sliding

drawer.setScrimColor(Color.TRANSPARENT);
        drawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.END);

My XML

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/navmenu_gradient"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>

<RelativeLayout android:id="@+id/holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

</RelativeLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    app:theme="@style/NavigationDrawerStyle"
    android:background="@drawable/navmenu_gradient"
    app:itemTextColor="@drawable/drawer_item_color"
    app:itemIconTint="@drawable/drawer_item_color"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.NavigationView"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

My OnDrawerSlide method

public void onDrawerSlide(View drawerView, float slideOffset) {

                                               // Scale the View based on current slide offset
                                               final float diffScaledOffset = slideOffset * (1 - END_SCALE);
                                               final float offsetScale = 1 - diffScaledOffset;
                                               contentView.setScaleX(offsetScale);
                                               contentView.setScaleY(offsetScale);

                                               // Translate the View, accounting for the scaled width
                                               final float xOffset = drawerView.getWidth() * slideOffset;
                                               final float xOffsetDiff = contentView.getWidth() * diffScaledOffset / 2;
                                               final float xTranslation = xOffset - xOffsetDiff;
                                               contentView.setTranslationX(xTranslation);


                                           }
arun
  • 143
  • 1
  • 9

1 Answers1

1

The problem is the drawer's elevation. So it casts a shadow. You can get rid of it by setting it to 0.

mDrawerLayout.setDrawerElevation(0);

or through xml

<android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:elevation="0dp"
        app:menu="@menu/navigation_menu" />
Rainmaker
  • 7,673
  • 4
  • 38
  • 63
  • Thank you @rainmaker, it worked great. By the way is there a way to give that elevation and shadow effect to the content view i.e the layout which occupies around 20 % of the screen in the screenshot i shared – arun Feb 12 '18 at 06:55
  • I mean to say my Main Screen view which we actually translate and animate. Can i apply elevation and shadow to it – arun Feb 12 '18 at 07:02
  • About the second question, yes you can do it on any layout as you did but put there not 0; but there're some requirements for a layout to cast a shadow, you can read here https://stackoverflow.com/questions/27477371/android-elevation-not-showing-a-shadow/27518160#27518160 – Rainmaker Feb 12 '18 at 07:03
  • Great it worked! Would you kindly accept the answer? – Rainmaker Feb 12 '18 at 07:05