Android软键盘适配问题
16lz
2021-12-04
记录:在android手机型号很多情况下,软键盘输入的都有兼容性问题以及弹出框有可能出现问题,遇到这样的问题还是需要考虑手机键盘建兼容:参考
if (!UtilsStyle.isHuaWei()) { et_input_art_comm.viewTreeObserver.addOnGlobalLayoutListener { val r = Rect() //获取当前界面可视部分 window.decorView.getWindowVisibleDisplayFrame(r) //获取屏幕的高度 val screenHeight = window.decorView.rootView.height //此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数 val heightDifference = screenHeight - r.bottom val layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) layoutParams.bottomMargin = 10 layoutParams.topMargin=10 ll_input.layoutParams = layoutParams } }} else { if (!UtilsStyle.isHuaWei()) { et_input_art_comm.viewTreeObserver.addOnGlobalLayoutListener { val r = Rect() //获取当前界面可视部分 window.decorView.getWindowVisibleDisplayFrame(r) //获取屏幕的高度 val screenHeight = window.decorView.rootView.height //此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数 val heightDifference = screenHeight - r.bottom val layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) layoutParams.bottomMargin = heightDifference/5 ll_input.layoutParams = layoutParams } }
注意的是:weight属性的优先级要高于LayoutParams设定的值,既然定死了所占比例,当然就无法同时设置其它的尺寸了,不然设置无效的,还有弹出框一定要设置宽高。
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- AIR Native Extension的使用(Android)一 : 打包ane
- android之BitMap
- Android中GPS定位的简单应用
- android之BitMap
- Android(安卓)开发中的倒计时
- [android]在上下文菜单的选中事件中获取列表选中的元素
- Android(安卓)EditText 设置行距不影响光标高度
- [Android]在App中使用相机