问题描述
我需要在 Android 2.2 及更高版本上对图标选择进行简单控制.
Gallery 对我来说是一个更好的解决方案,但它已被弃用,我必须改用 HorizontalScrollView
和 ViewPager
.
但是如何轻松迁移?在这种情况下如何使用这些类和控件?我试图找到这个主题的完整示例,但我找不到它.
在 ViewPager
中一次显示多个页面:
他的容器 (com.example.pagercontainer.PagerContainer
) 包装了 ViewPager
并在自身上调用 setClipChildren(false);
,所以即使尽管 ViewPager
专注于一个选定页面,但坐标超出 ViewPager
边界的其他页面仍然可见,只要它们适合 PagerContainer代码>.通过将
ViewPager
的大小设置为小于 PagerContainer
,ViewPager
可以将其页面调整为该大小,从而为其他页面留出空间.但是,PagerContainer
需要在触摸事件方面提供一些帮助,因为 ViewPager
只会在其自身可见边界上处理滑动事件,而忽略侧面可见的任何页面.
您可能还想筛选 这个 android-developers线程,有人在较新的Android版本上指出了这个问题.您需要禁用硬件加速由于 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.
This gist from Dave Smith shows a way to use ViewPager
to have visual results very similar to a Gallery
:
Quoting my blog post on the topic of showing multiple pages at a time in a 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.
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
.
这篇关于如何从 Gallery 迁移到 HorizontalScrollView &浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!