Android ResideMenu library, bottom of Fragment has Cropping issue

前端 未结 4 1288
礼貌的吻别
礼貌的吻别 2020-12-20 22:01

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

相关标签:
4条回答
  • 2020-12-20 22:09

    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.

    0 讨论(0)
  • 2020-12-20 22:24

    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.

    0 讨论(0)
  • 2020-12-20 22:26

    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);
        }
    
    0 讨论(0)
  • 2020-12-20 22:32

    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

    0 讨论(0)
提交回复
热议问题