计算listview上移距离,避免输入法遮挡
来源:互联网 发布:井冈山大学网络平台 编辑:程序博客网 时间:2024/05/01 00:03
项目中遇到个问题,点击listview的条目的评论按钮,显示输入法,这个时候listView条目内容会被输入法遮挡,这就需要将listView上移一段距离。一下是解决方案:
1、输入法弹出后必然会导致View重绘,可设置一个重绘完成的监听器
interface OnLayoutChangeAfterListener { void OnChangeAfter(int keyboard);//定义方法声明,用以传参 }
监听器的set方法
public void setListener(OnLayoutChangeAfterListener listener) { this.mListener = listener; } private OnLayoutChangeAfterListener mListener;
2、将类实现View.OnLayoutChangeListener,监听重绘
复写onLayoutChange方法
@Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if(oldBottom != 0 && bottom != 0 && ( oldBottom-bottom>100 ))//输入法弹出,计算输入法高度,也即要移动的距离 { mKeyBoard = oldBottom-bottom; if(mListener != null) { mListener.OnChangeAfter(mKeyBoard);//传参 } isOpenKeyBoard = true; mLlComment.setVisibility(View.VISIBLE); }else if(oldBottom != 0 && bottom != 0 && ( bottom-oldBottom>100 )) { isOpenKeyBoard = false; mLlComment.setVisibility(View.GONE); } }
1、计算移动距离
private void caculateScroll(View ll_comment_content) { int[] location = new int[2]; ll_comment_content.getLocationOnScreen(location); final int y = location[1];//计算view在屏幕上的Y轴位置 setListener(new OnLayoutChangeAfterListener() { //复写onChangeAfter方法 @Override public void OnChangeAfter(int keyboard) { int distance = y-keyboard-(int)mDensity*40; // mLvNotice.getRefreshableView().scrollListBy(distance);//scrollListBy()方法至少要求API19,故弃用 scrollVertical(mLvNotice.getRefreshableView(), mContext, distance); Log.e(TAG, "y:::::"+y+"------"+"keyboard:::::"+keyboard); } }); }
将listView移动到指定位置
private void scrollVertical(final ListView listView, Activity act, final int distance) { if(listView == null) { return; } act.runOnUiThread(new Runnable() { //执行自动化测试的时候模拟滑动需要进入UI线程操作 @Override public void run() { invokeMethod(listView, "trackMotionScroll", new Object[]{-distance, -distance}, new Class[]{int.class, int.class}); } }); }
利用反射找到要改写的方法,注意此处方法名trackMotionScroll// 垂直滑动指定距离
private void scrollVertical(final ListView listView, Activity act, final int distance) { if(listView == null) { return; } act.runOnUiThread(new Runnable() { //执行自动化测试的时候模拟滑动需要进入UI线程操作 @Override public void run() { invokeMethod(listView, "trackMotionScroll", new Object[]{-distance, -distance}, new Class[]{int.class, int.class}); } }); }
0 0
- 计算listview上移距离,避免输入法遮挡
- ListView 输入法框遮挡内容
- android:windowSoftInputMode属性详解 避免输入法面板遮挡问题
- iOS-监听键盘输入,视图整体上移或恢复-避免输入遮挡
- 计算ListView滚动的距离
- android listview 计算滑动距离
- 当输入法调出时,如何让界面自动上移,使输入法不会遮挡到主界面 android:windowSoftInputMode属性使用
- Android界面技巧:当输入法调出时,如何让界面自动上移,使输入法不会遮挡到主界面(Activity)
- uitextfield 键盘遮挡时上移
- UITableView键盘遮挡 自动上移
- 如何避免输入法弹出时遮挡住按钮或输入框
- Android如何避免输入法弹出时遮挡住按钮或输入框
- 输入法遮挡问题
- Android 输入法遮挡问题
- 输入法遮挡edittext解决办法
- Android 输入法遮挡问题
- popupWindow被输入法遮挡
- RN输入法遮挡TextInput
- 常见内存泄漏
- HashMap和Hashtable的区别
- sqlite3fun.c:155: first defined here execSqlite3 closeSqlite3 getSqlite3dbName编译不通过
- 在linux查看内存的大小
- 文本处理以及freetype的使用
- 计算listview上移距离,避免输入法遮挡
- Python文件处理
- Shell编程(1):变量
- [leetcode] 258. Add Digits
- GIT:git命令的使用分享下
- python3.5的安装 环境及notepad配置
- Map线程安全几种实现方法
- HDU_5791_Two(简单dp)
- 监督学习和无监督学习