2

I have created an Android application, in that I want to open slide menu from right side and when drawer is open I want to slide the view like attached image.

enter image description here

Code:

<android.support.v4.widget.DrawerLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start">


    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView_Right_Home"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="right"
         android:fitsSystemWindows="true"  />

</android.support.v4.widget.DrawerLayout>

For slide view I have used below code, but it's not working

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            View container = findViewById(R.id.ll);
            float moveFactor = (slideOffset - drawerView.getWidth());

            container.setTranslationX(moveFactor);

            drawer.bringChildToFront(drawerView);
            drawer.requestLayout();
        }
Sagar Zala
  • 4,854
  • 9
  • 34
  • 62
  • refer http://stackoverflow.com/questions/32439171/how-to-implement-drawer-menu-open-from-right-side – sasikumar May 08 '17 at 05:18
  • @sasikumar, I am able to open menu from right side, but I also want to slide view like attached image. – Sagar Zala May 08 '17 at 05:20
  • If I'm following you correctly, the translation - your `moveFactor` - would be `-drawerView.getWidth() * slideOffset`. The `slideOffset` is a fraction that ranges from `0f` to `1f`, not the actual width of anything. – Mike M. May 08 '17 at 05:29

2 Answers2

3

To slide the View to the left with the drawer, your moveFactor would be as follows:

float moveFactor = -drawerView.getWidth() * slideOffset;

Do note the negative sign in front of drawerView.getWidth().

The slideOffset is a fraction that ranges from 0f to 1f. Multiplying that by the drawer's width gives the actual offset, and negating it, we translate the content View to the left.

Mike M.
  • 38,532
  • 8
  • 99
  • 95
0

Try This

float moveFactor = drawerView.getWidth() * slideOffset;
container.setTranslationX(moveFactor);
Keerthivasan
  • 1,651
  • 1
  • 21
  • 47