在使用scrollview内部包含listview或者ExpandableListView的时候,实现屏幕整体滑动,在网上查到可以这样做:继承listview(或者ExpandableListView)复写onMeasure:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 加上下面的话即可实现listview在scrollview中滑动
heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
这个时候会出现一个问题就是scrollview的初始位置到了底部,不是顶部,可能你尝试过scrollto方法,但是scrollto是立刻执行,是看不到效果的,我们必须选择延迟执行滑动:scrollview.smoothScrollTo(0, 0)