Android ResideMenu library, bottom of Fragment has Cropping issue

好久不见. 提交于 2019-11-28 08:17:42

问题


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.


回答1:


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.




回答2:


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);
    }



回答3:


comment or Remove this method and your bottom of Fragment has Cropping issue solved.

fitSystemWindows()

Overrides deprecated method in 'android.view.View' as of API 20: Android 4.4W (KitKat Wear) Inspection info: This inspection reports where deprecated code is used in the specified inspection scope.




回答4:


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



来源:https://stackoverflow.com/questions/28952210/android-residemenu-library-bottom-of-fragment-has-cropping-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!