Recycling views inside a horizontal scrollview and

2019-09-08 15:14发布

问题:

I'm making an app with fairly complex UI. Its comparable to a horizontal list view that expands to a viewpager on being clicked. Presently, I've implemented this using the most basic approach. I simply inflate views inside a horizontalScrollView and inflate another subview with animation whenever user taps on any parent view.

This works perfectly fine and gives it a look of horizontal expandable listview. However, I feel this approach is highly inefficient since I keep on getting GC warnings almost every few seconds thereby reducing performance. And in this approach I'm not even recyling views like listview does.

My questions are:

  • Is there any other efficient way of doing this ?
  • How could I recycle views in my existing code like listview does?

Thanks!

(Please don't recommend using Gallery. My view is fairly complex)

回答1:

Is there any other efficient way of doing this ?

Use ViewPager or the open source HorizontalListView, both of which use the adapter pattern.