Android set navigation drawer list to open exact half of the screen for all device screen

set the width for ListView dynamically...

    mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) view.findViewById(R.id.top_sectionlist);

    int width = getResources().getDisplayMetrics().widthPixels/2;
    DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerList.getLayoutParams();
    params.width = width;
    mDrawerList.setLayoutParams(params);

You have to manual calculate the screen size and set dynamic width to the drawer layout at runtime, here is how to get device Screen Width and Height at run time

Using this code you can get runtime Display's Width & Height

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;

Now, you need to divide the width by 2

int newWidth=width/2;

Now set width to ListView like this

drawer_list.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,newWidth));

This will work for all the devices and will give uniform size across all.


here is my solution for others who need several percentage to show there navigation drawer.

Here, I use right navigation drawer & i show 15% of home screen when drawer move left.

  // convert your offset percent (here 15% ) into decimal by dividing 100 
    float offset = .15f * getResources().getDisplayMetrics().widthPixels ;
    float width = getResources().getDisplayMetrics().widthPixels - offset;
    DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) rightNavigationView.getLayoutParams();
    params.width = (int) width;
    rightNavigationView.setLayoutParams(params);