300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Android软键盘适配问题

Android软键盘适配问题

时间:2019-02-02 02:24:24

相关推荐

Android软键盘适配问题

记录:在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.bottomval layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)layoutParams.bottomMargin = 10layoutParams.topMargin=10ll_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.bottomval layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)layoutParams.bottomMargin = heightDifference/5ll_input.layoutParams = layoutParams}}

注意的是:weight属性的优先级要高于LayoutParams设定的值,既然定死了所占比例,当然就无法同时设置其它的尺寸了不然设置无效的,还有弹出框一定要设置宽高。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。