5

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 different. Android Logo is cropped when the side menu is closed. Part of the bottom screen is hidden under native navigation bar.

https://www.dropbox.com/s/wcwuat1bwoqa26v/correct1.png?dl=0

On the other hand, this picture is captured by galaxy s5 mini. You may notice the gap between top and below of the screen is the same amount. There is no problem at all.

It is the same ResideMenu library with different devices and android OS (lollipop & kitkat). I look at the layouts (residemenu.xml) to find something wrong; but everything seems correct to me. I couldn't find any solution to this problem. Is there any way to fix to scale main fragment correctly (same margin from top and bottom)? Please help me.

link to library: github.com/SpecialCyCi/AndroidResideMenu

Edit:

This link is the issue that I'm talking about with it's solution.

Orcun Sevsay
  • 1,310
  • 1
  • 14
  • 44

3 Answers3

11

I solved this issue by editing a method "ResideMenu.java" in ResideMenu library.

I made a few changes in a method called "fitSystemWindows"

before I made changes:

 @Override
    protected boolean fitSystemWindows(Rect insets) {

        this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top,
                viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + insets.bottom);
        insets.left = insets.top = insets.right = insets.bottom = 0;
        return true;
    }

after I made changes:

@Override
    protected boolean fitSystemWindows(Rect insets) {
        int bottomPadding=insets.bottom;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Resources resources = getResources();
            int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0) {
                bottomPadding += resources.getDimensionPixelSize(resourceId);
            }
        }
        this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top,
                viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + bottomPadding);
        insets.left = insets.top = insets.right = insets.bottom = 0;
        return true;
    }

This change solve my issue, part of the bottom screen hidden under native navigation bar.

I hope this solution be helpful anyone who encounter this kind of issue. Cheers.

Orcun Sevsay
  • 1,310
  • 1
  • 14
  • 44
  • What is viewActivity in your code? can you tell me i am getting error @MiloRambaldi – Anant Shah Aug 11 '16 at 07:25
  • 2
    It not works for all devices - for example - s6 edge - we get emply space in bottom – Lola Mar 10 '17 at 07:54
  • Hi, I'm unable to edit my ResideMenu.java, can you please explain how I can enable the edit option – Parthiban M Jun 29 '17 at 08:24
  • @ParthibanM you need to add ResideMenu as a module, not with gradle installation. Look at the installation section in [here](https://github.com/SpecialCyCi/AndroidResideMenu). So that you may change the library code in the module. [directory link](https://github.com/SpecialCyCi/AndroidResideMenu/tree/master/ResideMenu/src/com/special/ResideMenu) – Orcun Sevsay Jun 29 '17 at 08:30
1

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);
    }
Ankit Saini
  • 374
  • 5
  • 15
-1

I had this same issue and I solved this by editing a method in ResideMenu library.

Inside the library, you can acess a java class named "ResideMenu.java".

Edit the method as like this.

 private void setScaleDirection(int direction){

    int screenWidth = getScreenWidth();
    float pivotX;
    float pivotY = getScreenHeight() * 0.5f;

    if (direction == DIRECTION_LEFT){
        scrollViewMenu = scrollViewLeftMenu;
        pivotX  = screenWidth * 2.2f;
    }else{
        scrollViewMenu = scrollViewRightMenu;
        pivotX  = screenWidth * -0.5f;
    }

    ViewHelper.setPivotX(viewActivity, pivotX);
    ViewHelper.setPivotY(viewActivity, pivotY);
    ViewHelper.setPivotX(imageViewShadow, pivotX);
    ViewHelper.setPivotY(imageViewShadow, pivotY);
    scaleDirection = direction;
}

Here i made changes to

pivot x = (screenWidth * 2.2f) instead of (screenWidth * 0.5f).

try to manage the float value, it will solve your issue.

Thank you, Happy Coding

Joyal
  • 414
  • 7
  • 19
  • This is not the correct answer to my question. Changing pivotX's constant value does not help me about cropping issue. It only changes the sideMenu's screenWidth from left side of the screen. – Orcun Sevsay Jul 07 '15 at 13:59