监听软键盘显示并且整体向上移动

来源:互联网 发布:windows的相对路径 编辑:程序博客网 时间:2024/05/22 00:30
private void listenerSoftInput() {    final View activityRootView = findViewById(R.id.loginScroll);    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(        new ViewTreeObserver.OnGlobalLayoutListener() {      @Override     public void onGlobalLayout() {           int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();           if (heightDiff > 50) { // 如果高度差超过100像素,就很有可能是有软键盘...               scrollToTop();             } else {        }        }    });}//scrollview滑到顶部protected void scrollToTop() {    mHandler.postDelayed(new Runnable() {        @Override        public void run() {            loginScroll.scrollTo(10000,10000);        }    }, 100);

}

0 0