Android ListView与getView调用卡顿问题解决办法
AndroidListView与getView调用卡顿问题解决办法
解决办法1,设置ListView高度为固定值或者match_parent/ifll_parent
@Override
protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){
Log.d("onMeasure","onMeasure");
isOnMeasure=true;
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
}
@Override
protectedvoidonLayout(booleanchanged,intl,intt,intr,intb){
Log.d("onLayout","onLayout");
isOnMeasure=false;
super.onLayout(changed,l,t,r,b);
}
究其原因,无非是listview要动态计算有多少个view显示在里面,所以需要多次onMeasure,最后才onLayout,而onMeasure可能需要执行多次
这不就行了,我们在adapt里面的getview中,判断是否在onmeasure里,如果在,那么仅仅mInflater.inflate(R.layout.XXX),然后立刻返回这个convertView
如果不在onmeasure里,那么再去真正的onlayout
结合这种方法,成功解决了卡顿问题..
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!