开发者

Force ListView/BaseAdapter to inflate all needed views at the begining in android

开发者 https://www.devze.com 2023-03-26 03:53 出处:网络
I 开发者_高级运维have a rather expensive Layout that i inflate to a listview\'s childrens. If the listview shows 5 childrens eatch time getView() will inflate only 5 (maybe one-two more) of my expensi

I 开发者_高级运维have a rather expensive Layout that i inflate to a listview's childrens. If the listview shows 5 childrens eatch time getView() will inflate only 5 (maybe one-two more) of my expensive Layouts. And then reuse it. This process might take some time but it's ok.(It's at the same time i download data from the Internet so doesn't ruin the UX).

The problem is that if i scroll , at the beggining of the scrolling one convertView is null so the listview needs to inflate one more time. This is happening only the first time i scroll. Is there any way to avoid that? Notice that i don't resize any of the children or the Listview. Is there a way to inflate that extra view at the beggining so i avoid the Scrolling Lag?

UPDATE Also to be specific:

My listview shows 3and a half rows .. Meaning 4.The adapter inflates 5. What the adapter whats to inflate another one? Maybe there is a more elegant solution to that


Why not just create a cache of views when your activity is started, or in your adapter's constructor? getView() could return views from this cache if any are available, or create its own as it normally would if no cached views are available.

(I would not recommend creating more than n+1 views, though, where n is the number of views you expect to have on the screen at any one time. And I strongly recommend against ever trying to recycle old views back into the cache!)

0

精彩评论

暂无评论...
验证码 换一张
取 消