Android ListView與getView調用卡頓問題解決辦法
解決辦法1,設置ListView高度為固定值或者match_parent/ifll_parent
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Log.d("onMeasure", "onMeasure"); isOnMeasure = true; super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { 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
結合這種方法,成功解決了卡頓問題..
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答