HorizontalScrollView: CustomAdapter with getView() doesn't reuse convertViews like ListView

不想你离开。 提交于 2019-12-06 00:31:46

I think maybe you are confusing where the logic lies for rendering between View and Adapter. Using an Adapter does not cause view recycling behavior. It is the ListView itself, along with its parent, AbsListView, that implement the view recycling behavior. The Adapter is required by the ListView in order to properly populate the Views that are shown on screen as needed, but the logic for actually choosing which Views to display and when and how to recycle those views is not in the Adapter at all.

If you look at the source code for HorizontalScrollView and for ListView, you will see that they are dramatically different. They are not just the same thing in different orientations.

So, the long and short of it is that you will not be able to get the view recycling that you are looking for by using a HorizontalScrollView or even a simple descendent. If you want view recycling, you should check out the RecyclerView.

ScrollView keeps all child views in memory, so performance issue is common while using them.

Why not use some open source HorizontalListView library. On searching I got these two libs out of which i have used first one in one of my projects and it worked smoothly without any memory issues.

These libs are horizontal implementation of ListView, which does recycling of items for you based on which views are visible on screen. Scrollview is bad choice for inifinite scrolling view.

UPDATE: Now we have RecyclerView from Android itself, which supports horizontal scrolling as well, it also enforces the use of Viewholder pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!