您的位置:首页 > 其它

解决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);

}

});

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: