美文网首页
随软件盘弹出而升起相关操作

随软件盘弹出而升起相关操作

作者: 今天也要努力呀y | 来源:发表于2020-03-28 16:03 被阅读0次

    1.Recyclerview升起
    linearLayoutManager.setStackFromEnd(true);
    2.某一个布局升起
    工具类

    
    public class WithSoftUp {
        public static void addLayoutListener(final View main, final View scroll) {
            main.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    
                @Override
    
                public void onGlobalLayout() {
    
                    Rect rect = new Rect();
    
                    main.getWindowVisibleDisplayFrame(rect);
    
                    int screenHeight = main.getRootView().getHeight();
    
                    int mainInvisibleHeight = main.getRootView().getHeight() - rect.bottom;
    
                    if (mainInvisibleHeight > screenHeight / 4) {
    
                        int[] location = new int[2];
    
                        scroll.getLocationInWindow(location);
    
                        int srollHeight = (location[1] + scroll.getHeight()) - rect.bottom;
    
                        main.scrollTo(0, srollHeight);
    
                    } else {
    
                        main.scrollTo(0, 0);
    
                    }
    
                }
    
            });
    
    
        }
    }
    
    

    使用:

            WithSoftUp.addLayoutListener(findViewById(R.id.parent), linearLayout);
    

    相关文章

      网友评论

          本文标题:随软件盘弹出而升起相关操作

          本文链接:https://www.haomeiwen.com/subject/vzqsuhtx.html