listview 设置某行位置位于键盘顶部
来源:互联网 发布:苹果6突然无法加入网络 编辑:程序博客网 时间:2024/06/05 09:01
最近需要做个功能,就像微信朋友圈那样点击某个item时,会调整item的位置在输入框上面。在网上找了些资料完成了这个功能,记录一下
Window mRootWindow = getWindow(); View mRootView = mRootWindow.getDecorView().findViewById( android.R.id.content); mRootView.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { Rect r = new Rect(); View view = mRootWindow.getDecorView(); view.getWindowVisibleDisplayFrame(r); //进入应用后会首先调一次这个方法,contentHeight为去掉状态栏屏幕的高度 if (isFirst) { contentHeight = r.bottom - r.top; isFirst = false; } // 当输入法弹起时r.bottom-r.top为输入法顶部到状态栏底部的高度 if (r.bottom - r.top != contentHeight) { int lastHeight = 0; if (!isKeyboard) {//输入法弹起的一个flag,此处设置主要是因为下面调整listview时onGlobalLayout()方法会循环调用,设置后避免它循环进入方法 height = 0; //curPosition为当前点击的行position for (int i = curPosition; i >= 0; i--) { View item = adapter.getView(i, null, listview); item.measure(0, 0);//此处item(item可能为header)的根布局为LinearLayout,否则会报空指针异常 if(i==curPosition){ //currentHeight 为当前行的高度 currentHeight = item.getMeasuredHeight(); } //height为计算当前行底部到listview控件顶部,此处listview之上没有其他视图了 height += item.getMeasuredHeight(); if (height > r.bottom - r.top) { listview.setSelectionFromTop( curPosition, r.bottom- r.top- currentHeight);//当前行到顶部的偏移量 isKeyboard = true; break; } } } } } });
0 0
- listview 设置某行位置位于键盘顶部
- android 输入法弹出键盘把listview顶上去,保留顶部标题栏位置不动
- ScrollView嵌套ListView设置默认位置为最顶部的解决方案
- scrollView嵌套listView,重新设置listview高度解决冲突,但打开activity之后,初始位置不是顶部解决方案
- scrollview起始位置如何设置为顶部
- scrollview起始位置如何设置为顶部
- scrollview起始位置如何设置为顶部
- ScrollView嵌套ListView起始位置不是顶部,ScrollView嵌套GridView起始位置不是顶部解决方法
- ScrollView嵌套ListView,GridView起始位置不是顶部
- 处理ScrollView内嵌ListView起始位置不是顶部问题
- ScrollView嵌套ListView默认位置不是最顶部的解决方案
- ScrollView嵌套ListView显示的位置不在顶部,而在ListView展开的位置
- scrollview嵌套listview运行后最先显示出来的位置不在顶部而在顶部问题
- 设置RecyclerView的位置(点击回到顶部)
- 关于ScrollView嵌套listView默认位置为listview顶部的问题
- listview设置显示位置的api
- Android中保存并设置ListView位置
- Scrollview 界面打开不是位于顶部
- 万能适配器,其实不是万能的,但用着会方便很多。
- SSH key and passwordless login basics for developers
- 正则表示式字符收纳
- 根据前序遍历和中序遍历构造二叉树
- Android抓取崩溃日志
- listview 设置某行位置位于键盘顶部
- Activity启动模式
- Linux ssh免密码登陆配置
- 非常有用的php代码片段
- 微软简讯20160113 终止framework 4.0 4.5 4.5.1 的支持
- 国外用spring开发的开源系统值得学习
- 函数调用过程探究
- 创建型——简单工厂模式
- 深入浅出RxJava(一:基础篇)