问题
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