android进阶-----解决scrollview嵌套listview的问题
在android开发中,经常会碰到在ScrollView中嵌套ListView的界面的开发,在ScrollView中嵌套ListView会带来几个问题,经过反复的实践,总结出完美解决的办法如下:
1.继承ListView 复写其中的方法
@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //实现listview在scrollview中动 int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); System.out.println("expandSpec = " + expandSpec); super.onMeasure(widthMeasureSpec, expandSpec); }
2.在界面初始化或者数据加载完毕时让ScrollView滚动到顶部:
ScrollView sv = (ScrollView) findViewById(R.id.main_scrollview); sv.smoothScrollTo(0, 0);
相关推荐
JayFighting 2020-06-04
XDgaozhan 2013-07-10
luoj 2011-08-17
AndroidGA 2015-03-22
fuzhangandroid 2012-02-03
PiYuqing 2016-12-26
RickyLee 2015-07-26
superxlcr 2015-03-22
ZhongGuanGuan 2014-10-31
yarkey0 2014-10-22
翟浩浩Android 2014-02-24
OuNuo0 2013-08-05
PrisonJoker 2013-07-10
zmmzmm 2013-01-25
fanjunjian 2012-10-18
housezhu 2012-10-15
yuyu00 2012-05-07