简体   繁体   中英

Alternatives to android.widget.Gallery (not the Gallery app)

Apology if this has been asked before, but I've tried googling the topic without any good result. Basically I'm trying to find a replacement for Gallery widget which Google has decided to deprecate. So far I have the following candidates:

  1. ViewPager. Unfortunately (as far as I know), you can only display one View at a time. I know someone has posted a workaround for this here: https://gist.github.com/devunwired/8cbe094bb7a783e37ad1 . But I'm having problem with this approach. On my phone, three images are shown (horizontally). The most left & the most right are static, while the middle one is scrollable (like what ViewPager should do). ie the most left & most right image doesnt scroll as I scroll the ViewPager. So I have to turn down this solution.

  2. GridView. Seems good, but it seems like GridView is designed to be scrollable horizontally & vertically. I just want one row, and scroll horizontally. As far as I know, Gallery is not designed with this in mind.

  3. HorizontalScrollView. Another one that Google has suggested in the Javadocs (apart from ViewPager). Seems like a good one to use, but... if i understand it correctly, using this approach all the contents are going to be instantiated up front. There is no lazy loading..

So I'm puzzled right here. Seems like the best solution is to either use ViewPager with only one View at a time (undesirable for what I want), or stick with Gallery.

What do people think??

Thanks in advance!

android.support.v4.view.ViewPager is the definitive answer.

You can display any number of pages ( View s), it all depends on the PagerAdapter . It has a method .getPageWidth(position) , which gets called for each page. If it returns 0.5, for example, the page will only be half the width of the ViewPager .

Don't stick with Gallery , as it has memory leak issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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