zoukankan      html  css  js  c++  java
  • 120、键盘弹出界面上移

    添加到activity 到 AndroidManifest.xml 中的属性
    android:windowSoftInputMode="adjustPan|stateHidden" 键盘会覆盖屏幕
    android:windowSoftInputMode="adjustUnspecified|stateHidden" >屏幕整体上移

    import android.graphics.Rect;  
    import android.view.View;  
    import android.view.ViewTreeObserver.OnGlobalLayoutListener;  
      
    /** 
     * 当弹出键盘时,调整布局,向上移动,避免遮挡输入的edit控件 */  
    public class KeyboardAdjustUtil {  
        /** 
         * @param root 最外层布局,需要调整的布局 
         * @param scrollToView 被键盘遮挡的scrollToView,滚动root,
    * 使scrollToView在root可视区域的底部
    */ public static void controlKeyboardLayout(final View root, final View scrollToView) { root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); // 获取root在窗体的可视区域 root.getWindowVisibleDisplayFrame(rect); // 获取root在窗体的不可视区域高度(被其他View遮挡的区域高度) int rootInvisibleHeight = root.getRootView().getHeight() - rect.bottom; // 若不可视区域高度大于100,则键盘显示 if (rootInvisibleHeight > 10) { int[] location = new int[2]; // 获取scrollToView在窗体的坐标 scrollToView.getLocationInWindow(location); // 计算root滚动高度,使scrollToView在可见区域 int srollHeight = (location[1] + 3 * scrollToView.getHeight()) - rect.bottom; root.scrollTo(0, srollHeight); } else { // 键盘隐藏 root.scrollTo(0, 0
    ); } } }); } }
  • 相关阅读:
    [PAT] 1012 The Best Rank (25 分)Java
    scroll-view 隐藏滚动条
    python bool
    wx小程序 button 属性open-typ 用法 按钮分享
    python str 的常用方法
    node global文件夹和chace文件夹位置全局位置修改
    wx.showModal() 内容如何换行?
    自定义导航栏头部 并简单设置标题和返回按键
    jquery绑定事件如何传递参数
    复习第一天内容
  • 原文地址:https://www.cnblogs.com/androidsj/p/6344739.html
Copyright © 2011-2022 走看看