Android: ListView in HorizontalScrollView performance issues

早过忘川 提交于 2019-12-08 01:42:41

问题


I have a need for both horizontal and vertical scrolling of some data in my app. I've overridden HorizontalScrollView and I've allowed it to take an Adapter to populate its data. It behaves much like a horizontal ListView would behave, except I'm not doing any view recycling. Each item in my custom HorizontalScrollView is a ListView whose items are also populated with an Adapter. Each item in the ListView is a complex view.

I'm able to scroll horizontally, and vertically just fine except that it's performance is a bit chunky. The getView() method in the adapter for populating the custom HorizontalScrollView is only called when the Adapter is first set on the view. However, I noticed that getView() is constantly being called for the ListViews in the HorizontalScrollView. I'm wondering is this is the performance problem?

This question points out a supposed documentation bug pertaining to using a ListView inside of a HorizontalScrollView, but the same warning is not given in the documentation for the vertically scrolling ScrollView documentation.

Will I have performance issues if I put ScrollViews inside of the HorizontalScrollView?


回答1:


Giving the ListView a dip value for layout_height did the trick. Not setting a height was causing the ListView to keep measuring, calling getView, etc.



来源:https://stackoverflow.com/questions/7681581/android-listview-in-horizontalscrollview-performance-issues

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