ListView,GridView 与scrollView嵌套使用出现的问题:
1, LV 与 GV显示不完整:
写一个类 继承LV或GV
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
2,LV刷新数据会自动滚到LV处:
java中
listView.setFoucse(false);
scrollView.scrollTo(0,0);
3.scrollview
滚动到底部,内部空间焦点会刷新的问题
滚动到底部的方法是
scrollView.fullScroll(View.FOCUS_DOWN);
可以使用下方代码替换,不刷新焦点,只改变位置
/**
* scroll
* innerView :scrollView内部的主布局
**/
public void scrollToBottom(final ScrollView scroll, final View innerView) {
if (handler == null) {
handler = new Handler();
}
handler.post(() -> {
if (scroll == null || innerView == null) {
return;
}
int offset = innerView.getMeasuredHeight() - scroll.getHeight();
if (offset < 0) {
offset = 0;
}
scroll.smoothScrollBy(0, offset);
});
}