Android 软键盘遮挡控件

Android About 860 words

解决方法

public 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 mainInvisibleHeight = main.getRootView().getHeight() - rect.bottom;
            int screenHeight = main.getRootView().getHeight();//屏幕高度
            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);
            }
        }
    });
}
Views: 2,367 · Posted: 2019-04-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh