android软键盘弹出引起的各种不适终极解决方案
以下描述如何解决ListView高度小于0时出现的UI问题。
创建RelativeLayout的子类TxrjRelativeLayout
public class TxrjRelativeLayout extends RelativeLayout {
private int count = 0;
public TxrjRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.e("txrjsms " + count++, "=>onSizeChanged called! w=" + w
+ ",h=" + h + ",oldw=" + oldw + ",oldh=" + oldh);
}
}
使用TxrjRelativeLayout 提供sms_message_list.xml文件中的根节点RelativeLayout。
运行程序查看日志:
07-20 12:56:54.774: E/txrjsms 0(23195): =>TxrjRelativeLayout.onSizeChanged called! w=480,h=762,oldw=0,oldh=0
07-20 12:56:54.784: E/txrjsms 0(23195): =>TxrjListView.onSizeChanged called! w=480,h=605,oldw=0,oldh=0
07-20 12:56:55.024: E/txrjsms 1(23195): =>TxrjListView.onSizeChanged called! w=480,h=373,oldw=480,oldh=605
07-20 12:57:08.377: E/txrjsms 1(23195): =>TxrjRelativeLayout.onSizeChanged called! w=480,h=353,oldw=480,oldh=762 // 762-353=409
07-20 12:57:08.377: E/txrjsms 2(23195): =>TxrjListView.onSizeChanged called! w=480,h=-36,oldw=480,oldh=373 // 373-(-36)=409
07-20 12:57:48.396: E/txrjsms 3(23195): =>TxrjListView.onSizeChanged called! w=480,h=-37,oldw=480,oldh=-36
07-20 12:57:57.164: E/txrjsms 4(23195): =>TxrjListView.onSizeChanged called! w=480,h=-9,oldw=480,oldh=-37
07-20 12:58:00.338: E/txrjsms 5(23195): =>TxrjListView.onSizeChanged called! w=480,h=19,oldw=480,oldh=-9
07-20 12:58:06.864: E/txrjsms 6(23195): =>TxrjListView.onSizeChanged called! w=480,h=47,oldw=480,oldh=19
07-20 12:58:07.745: E/txrjsms 7(23195): =>TxrjListView.onSizeChanged called! w=480,h=75,oldw=480,oldh=47
07-20 12:58:08.776: E/txrjsms 8(23195): =>TxrjListView.onSizeChanged called! w=480,h=103,oldw=480,oldh=75
07-20 12:58:09.647: E/txrjsms 9(23195): =>TxrjListView.onSizeChanged called! w=480,h=131,oldw=480,oldh=103
07-20 12:58:10.477: E/txrjsms 10(23195): =>TxrjListView.onSizeChanged called! w=480,h=159,oldw=480,oldh=131
07-20 12:58:11.378: E/txrjsms 11(23195): =>TxrjListView.onSizeChanged called! w=480,h=187,oldw=480,oldh=159
07-20 12:58:12.299: E/txrjsms 12(23195): =>TxrjListView.onSizeChanged called! w=480,h=196,oldw=480,oldh=187
07-20 12:58:15.813: E/txrjsms 2(23195): =>TxrjRelativeLayout.onSizeChanged called! w=480,h=419,oldw=480,oldh=353 // 419-353=66
07-20 12:58:15.813: E/txrjsms 13(23195): =>TxrjListView.onSizeChanged called! w=480,h=262,oldw=480,oldh=196
07-20 12:58:15.913: E/txrjsms 3(23195): =>TxrjRelativeLayout.onSizeChanged called! w=480,h=762,oldw=480,oldh=419 // 762-419=343
07-20 12:58:15.923: E/txrjsms 14(23195): =>TxrjListView.onSizeChanged called! w=480,h=605,oldw=480,oldh=262
通过计算,可以得出软键盘的高度是409,其中候选区高度是66,键盘区高度是343。
实现TxrjListView扩展ListView,在onSizeChanged()方法中根据当前高度判断是否将ListView设定为不可见。
如果高度小于等于0,那么将ListView设定为不可见,然后就不会出现文章adjustResize和adjustPan的比较中提到的UI重叠BUG。
public class TxrjListView extends ListView {
public int count = 0;
public TxrjListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.e("txrjsms " + count++, "=>TxrjListView.onSizeChanged called! w=" + w
+ ",h=" + h + ",oldw=" + oldw + ",oldh=" + oldh);
setVisibility(h <= 0 ? View.INVISIBLE : View.VISIBLE); // 高度小于等于0不可见,高度大于0可见。
}
}
android软键盘弹出引起的各种不适终极解决方案的更多相关文章
- Android软键盘弹出,覆盖h5页面输入框问题
之前我们在使用vue进行 h5 表单录入的过程中,遇到了Android软键盘弹出,覆盖 h5页面 输入框 问题,在此进行回顾并分享给大家: 系统:Android 条件:当输入框在可视区底部或者偏下的位 ...
- Android 软键盘弹出,界面整体上移
在做搜索功能的时候,点击搜索框,搜索框获取焦点,键盘弹出:现在问题出来了,android软键盘弹出的时候,android整个界面上移,布局被挤压,很难看:要解决这个问题,我们需要用到 windowSo ...
- Android软键盘弹出时布局问题
最近项目需要做一个类似聊天室的模块,基于Socket实现的,这部分稍后一段时间再做总结,功能上的相关点都实现了小例子也做出来了,最后发现一个比较腻歪的问题就是软键盘弹出时总是会把标题“挤出”屏幕,(无 ...
- Android 软键盘弹出时把原来布局顶上去的解决方法
键盘弹出时,会将布局底部的导航条顶上去. 解决办法: 在mainfest.xml中,在和导航栏相关的activity中加: <activity android:name=& ...
- Android软键盘弹出时把布局顶上去的解决方法
原文: 解决Andriod软键盘出现把原来的布局给顶上去的方法(转) 链接:http://blog.sina.com.cn/s/blog_9564cb6e0101g2eb.html 决方法,在main ...
- Android 判断软键盘弹出并隐藏的简单完美解决方案
最近项目中有一个编辑框,下面是个ListView.在触发编辑框弹出软键盘后,ListView还能滑动,并且ListView的item还能响应单击.这样的体验效果很不好.于是便想在滑动或单击item时判 ...
- Android 软键盘弹出时把布局顶上去,控件乱套解决方法
解决办法:方法一:在你的activity中的oncreate中setContentView之前写上这个代码getWindow().setSoftInputMode(WindowManager.Layo ...
- android软键盘弹出隐藏的监听
通过网上搜索关于软键盘的隐藏弹出的监听,有几种方式,其中最有效的方式是在View的Onlayout()里面做文章 具体代码: 将布局视图自定义,重写onlayout()方法,然后在主Activity里 ...
- edittext禁止android软键盘弹出
1. EditText ed=(EditText) findViewById(R.id.test); ed.clearFocus(); 2. 在AndroidMainfest.xml中选择哪个acti ...
随机推荐
- Generate Parentheses leetcode java
题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed paren ...
- jQuery实现锚点跳转(就一行代码)
/* 锚点跳转 */ function anchor(p,fn) { $("html,body").animate({ scrollTop: $("#" + p ...
- C++ 学习路线和看法
C++ 学习路线和看法 原文地址:http://shundacao.blog.163.com/blog/static/1340404812010101982751101/ C++大体分为C++ ...
- JS滚轮事件onmousewheel
典型的应用时鼠标滚轮滚动控制图片或者文字的大小,例如此类的转动鼠标滚轮实现缩放等等交互效果中,会用到 Mousewheel 事件.在大多数浏览器(IE6, IE7, IE8, Opera 10+, S ...
- centos:时间同步
转自:https://blog.csdn.net/u011391839/article/details/62892020 Linux的时间分为System Clock(系统时间)和Real Time ...
- Vs2013 坑爹的Target framework问题
之前的一个项目是使用Vs2008来开发的,因为这段时间家里有事情所以只能跟经理协商在家里来做此项目,因为家里的VS是2013的所以在迁移时没有什么问题 但今天我更改一个类库的文件后重新生成解决方案结果 ...
- SQLSERVER 免费对比数据库结构和数据的工具支持:SQL Server 2012, SQL Server 2008 and SQL Server 2005
New xSQL Schema Compare - version 5 Compare the schemas of two SQL Server databases, review differen ...
- 【Python】使用torrentParser1.03对单文件torrent的分析结果
C:\Users\horn1\Desktop\python\42-torrentParser>python torrentParser.py 文件名=./5.torrent 文件结构: anno ...
- yii源码二 -- interfaces
path:framework/base/interfaces.php overview:This file contains core interfaces for Yii framework. in ...
- FPipe, CMD命令行下的端口重定向工具
英文文档: FPipe v2. - TCP/UDP port redirector. Copyright (c) by Foundstone, Inc. http://www.foundstone.c ...