我需要在 Android 2.2 及更高版本上选择图标的简单控制。
Gallery 对我来说是一个更好的解决方案,但它已被弃用,我必须改用 HorizontalScrollView
和 ViewPager
。
但是如何轻松迁移?在这种情况下如何使用这些类和控件?我试图找到这个主题的完整示例,但找不到。
最佳答案
This gist from Dave Smith显示了一种使用 ViewPager
获得与 Gallery
非常相似的视觉结果的方法:
引用 my blog post on the topic在 ViewPager
中一次显示多个页面:
His container (
com.example.pagercontainer.PagerContainer
) wraps theViewPager
and callssetClipChildren(false);
on itself, so even though theViewPager
is focused on one selected page, other pages that have coordinates beyond theViewPager
bounds are still visible, so long as they fit within thePagerContainer
. By sizing theViewPager
to be smaller than thePagerContainer
, theViewPager
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, asViewPager
will only handle swipe events on its own visible bounds, ignoring any pages visible to the sides.
您可能还想筛选 this android-developers thread ,有人在较新的 Android 版本上指出了这个问题。您需要禁用硬件加速 due to a bug in ViewPager
.
关于android - 如何从 Gallery 迁移到 HorizontalScrollView & ViewPager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12239886/