Android move main content to reveal drawer right side

I'd like to create a navigation drawer effect, but rather than the drawer sliding out from the right.I Created code and my code working perfect when my slide menu is left side.this is a my java code.

DrawerLayout drawerLayout;
View drawerView;
View drawerContent;
View mainContent;
ActionBarDrawerToggle toggle;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerView = findViewById(R.id.drawer_view);
    drawerContent = findViewById(R.id.drawer_content);
    mainContent = findViewById(R.id.main_content);
    toggle = new ActionBarDrawerToggle(
            TestLayout.this,
            drawerLayout,
            R.drawable.ic_drawer,
            R.string.u_drawer_call_center,
            R.string.u_drawer_call_center
    ) {

        @Override
        public void onDrawerSlide(View drawer, float slideOffset)
        {
            super.onDrawerSlide(drawer, slideOffset);

            drawerContent.setX(drawerView.getWidth() * (1 - slideOffset));
            mainContent.setX(drawerView.getWidth() * slideOffset);

        }
        public void onDrawerClosed(View view) {
        }

        public void onDrawerOpened(View drawerView) {

        }
    };
    drawerLayout.setDrawerListener(toggle);
    drawerLayout.closeDrawer(drawerView);
    drawerContent.setX(drawerView.getWidth());
}

} as i said i can move main content when my slide menu is left side.but now i want slide menu right side.i rewrited my xml code but i can't move main content this is a my xml code

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">

<FrameLayout android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#cccccc" />

<LinearLayout android:id="@+id/drawer_view"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="right">

    <LinearLayout android:id="@+id/drawer_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

    </LinearLayout>

</LinearLayout>

i also changed source code

drawerContent.setX(drawerLayout.getWidth() - (drawerView.getWidth() * (1 - slideOffset)));
mainContent.setX(drawerLayout.getWidth() - (drawerView.getWidth() *   slideOffset));

but this code not working.I don't know how to use my code when i have slide menu right side. if anyone knows solution please help me thanks everyone

Answers


Other than changing the layout_gravity on the drawer_view as you've already done, the necessary changes are minor. In my original code, negate every occurrence of drawerView.getWidth(). That is:

toggle = new ActionBarDrawerToggle(...) {
    ...

    @Override
    public void onDrawerSlide(View drawer, float slideOffset) {
        super.onDrawerSlide(drawer, slideOffset);

        drawerContent.setX(-drawerView.getWidth() * (1 - slideOffset));
        mainContent.setX(-drawerView.getWidth() * slideOffset);

        ...
    }
};
...

drawerContent.setX(-drawerView.getWidth());

You will then need to override MainActivity's onOptionsItemSelected() method as follows:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        if(drawerLayout.isDrawerOpen(Gravity.END)) {
            drawerLayout.closeDrawer(Gravity.END);
        }
        else {
            drawerLayout.openDrawer(Gravity.END);
        }
        return true;
    }
    ...

    return super.onOptionsItemSelected(item);
}

Need Your Help

How to pass property when using Ajax in Struts 2

javascript java jquery ajax struts2

Using Struts 2 with Ajax when I tried to submit the form the property are not passed to action class hence I am getting null.

Android Dropdown (Select) CSS

css android select drop-down-menu

I'm currently writing some stylesheets for mobile browsers and have come across a strange issue in the Android browser. When changing the font-size CSS attribute of a text box the box gets bigger to