解决listview底部变化遮盖
2015-10-27 11:39
344 查看
listView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
System.out.println("layout changed");
if (bottom > 0 && oldBottom > 0 && bottom != oldBottom) {
listView.removeOnLayoutChangeListener(this);
scrollRunnable.setBottomValue(bottom, oldBottom);
scrollRunnable.run();
listView.addOnLayoutChangeListener(this);
}
}
});
ScrollRunnable scrollRunnable = new ScrollRunnable();
class ScrollRunnable implements Runnable {
private int bottomValue;
private int oldBottomValue;
public void setBottomValue(int bottom, int oldBottom) {
this.bottomValue = bottom;
this.oldBottomValue = oldBottom;
}
@Override
public void run() {
final ViewGroup parent = (ViewGroup) listView.getParent();
parent.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top,
int right, int bottom, int oldLeft, int oldTop,
int oldRight, int oldBottom) {
parent.removeOnLayoutChangeListener(this);
// scrool2Bottom();
int result = bottomValue - oldBottomValue;
int scrollValue = result;
// listView.scrollBy(0, -result);
int firstVisiblePosition = listView
.getFirstVisiblePosition();
int firstVisibleTop = listView.getChildAt(0).getTop();
listView.setSelectionFromTop(firstVisiblePosition,
scrollValue + firstVisibleTop);
}
});
}
}
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
System.out.println("layout changed");
if (bottom > 0 && oldBottom > 0 && bottom != oldBottom) {
listView.removeOnLayoutChangeListener(this);
scrollRunnable.setBottomValue(bottom, oldBottom);
scrollRunnable.run();
listView.addOnLayoutChangeListener(this);
}
}
});
ScrollRunnable scrollRunnable = new ScrollRunnable();
class ScrollRunnable implements Runnable {
private int bottomValue;
private int oldBottomValue;
public void setBottomValue(int bottom, int oldBottom) {
this.bottomValue = bottom;
this.oldBottomValue = oldBottom;
}
@Override
public void run() {
final ViewGroup parent = (ViewGroup) listView.getParent();
parent.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top,
int right, int bottom, int oldLeft, int oldTop,
int oldRight, int oldBottom) {
parent.removeOnLayoutChangeListener(this);
// scrool2Bottom();
int result = bottomValue - oldBottomValue;
int scrollValue = result;
// listView.scrollBy(0, -result);
int firstVisiblePosition = listView
.getFirstVisiblePosition();
int firstVisibleTop = listView.getChildAt(0).getTop();
listView.setSelectionFromTop(firstVisiblePosition,
scrollValue + firstVisibleTop);
}
});
}
}
相关文章推荐
- Android ViewPager轮播图
- Missing Number - LeetCode
- Android开源网络电话Sipdroid
- jQuery.noop
- linux目录结构详细介绍
- C#学习之三层架构实例
- 分享一个超级赞的github的资源整理
- XML和HTML常用转义字符
- js 数据类型转换
- LeetCode OJ:Unique Binary Search Trees(唯一二叉搜索树)
- Timus Online Judge 1018 Binary Apple Tree(树型dp)
- 堆ADT_Heap
- 写一个新的xtype
- 从电容的名称认识电容的作用
- Direct3D开启垂直同步的三种方法
- qt环境变量配置
- 音频视频拍照教程说明
- Android控件RecyclerView和ListView的异同
- UML类图几种关系的总结
- Android之WifiManager