简体   繁体   English

添加项目时ListView闪烁

[英]ListView blinks when adding items

In my app i have a ListView with an ArrayAdapter. 在我的应用程序中,我有一个带有ArrayAdapter的ListView。 Every Item contains a picture, which takes a bit of time to render. 每个项目都包含一张图片,需要花费一些时间来渲染。 Now i want to add items dynamicly at the end of the List. 现在我想在列表末尾动态添加项目。 The problem is, that wehenever add() is called my List blinks, because notifyDataSetChanged() is called and my pictures take a few milliseconds to render. 问题是,无论何时调用add(),我的列表都会闪烁,因为调用notifyDataSetChanged(),并且我的图片需要花费几毫秒的渲染时间。 I tried to avoid this by calling setNotifyOnChange(false). 我试图通过调用setNotifyOnChange(false)来避免这种情况。 I solved the blinking with that, but unfortunately it is only updating the "length" of my list irregularly. 我解决了闪烁问题,但是不幸的是,它只是不定期地更新列表的“长度”。 Is there some way to update the "length" of my listview, without updating the views which are shown? 有什么方法可以更新列表视图的“长度”,而无需更新显示的视图?

I would agree that the UI thread should be avoided, especially for lists, and especially when using images for each list item. 我同意应该避免使用UI线程,尤其是对于列表,尤其是对于每个列表项使用图像时。 Perhaps you need to find a more robust list adapter that is geared towards images? 也许您需要找到一个针对图像的更强大的列表适配器? See this question for some helpful ideas/hints at how to improve your own list. 有关如何改善自己的清单的一些有用的想法/提示,请参见此问题

Also, the AndroidQuery (AQuery) library may be useful when fetching images for use in the arrayadapter: Image Loading via AQuery . 同样,在获取要在arrayadapter中使用的图像时,AndroidQuery(AQuery)库可能会很有用: 通过AQuery加载图像 It takes care of the burden of image caching as well, which I have found to be quite useful. 它也解决了图像缓存的负担,我发现它非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM