`
wangjie2013
  • 浏览: 168712 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

初始化ScrollView位置到顶部

阅读更多

    在使用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)

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics