Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

android - How to migrate from Gallery to HorizontalScrollView & ViewPager?

I need simple control for icon choosing on Android 2.2 and higher.
Gallery was a better solution for me, but it is deprecated and I have to use HorizontalScrollView and ViewPager instead.
But how to migrate easy? How to use this classes and controls in this case? I've try to find complete example for this subject, but I can't find it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This gist from Dave Smith shows a way to use ViewPager to have visual results very similar to a Gallery:

Gallery-style ViewPager

Quoting my blog post on the topic of showing multiple pages at a time in a ViewPager:

His container (com.example.pagercontainer.PagerContainer) wraps the ViewPager and calls setClipChildren(false); on itself, so even though the ViewPager is focused on one selected page, other pages that have coordinates beyond the ViewPager bounds are still visible, so long as they fit within the PagerContainer. By sizing the ViewPager to be smaller than the PagerContainer, the ViewPager can size its pages to that size, leaving room for other pages to be seen. PagerContainer, though, needs to help out a bit with touch events, as ViewPager will only handle swipe events on its own visible bounds, ignoring any pages visible to the sides.

You might also want to sift through this android-developers thread, where somebody pointed out an issue with this on newer Android versions. You need to disable hardware acceleration due to a bug in ViewPager.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...