https://www.dropbox.com/s/lykyutdlo6386il/nexus%205%202.png?dl=0
This picture is captured by nexus 5. As you can see the gap between top and bottom of screen is diff
Found Most stable solution
public Point getNavigationBarSize(Context context) {
Point appUsableSize = getAppUsableScreenSize(context);
Point realScreenSize = getRealScreenSize(context);
// navigation bar on the right
if (appUsableSize.x < realScreenSize.x) {
return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
}
// navigation bar at the bottom
if (appUsableSize.y < realScreenSize.y) {
return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
}
// navigation bar is not present
return new Point();
}
public Point getAppUsableScreenSize(Context context) {
WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}
public Point getRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
try {
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (IllegalAccessException e) {} catch (InvocationTargetException e) {} catch (NoSuchMethodException e) {}
}
return size;
}
And set padding of main layout
setPadding(getPaddingLeft(),
getPaddingTop(), getPaddingRight(),
getNavigationBarSize(getContext()).y);
Edit : Keep this code inside attachToActivity() method of ResideMenu.java
if (getNavigationBarSize(getContext()).x > 0 && getNavigationBarSize(getContext()).y > 0) {
this.postDelayed(new Runnable() {
@Override
public void run() {
setPadding(getPaddingLeft(),
getPaddingTop(), getPaddingRight(),
getNavigationBarSize(getContext()).y);
}
}, 100);
}