如何从 Gallery 迁移到 Horizo​​ntalScrollView &浏览器? [英] How to migrate from Gallery to HorizontalScrollView & ViewPager?

查看:14
本文介绍了如何从 Gallery 迁移到 Horizo​​ntalScrollView &浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Android 2.2 及更高版本上对图标选择进行简单控制.
Gallery 对我来说是一个更好的解决方案,但它已被弃用,我必须改用 Horizo​​ntalScrollViewViewPager.
但是如何轻松迁移?在这种情况下如何使用这些类和控件?我试图找到这个主题的完整示例,但我找不到它.

解决方案

ViewPager 中一次显示多个页面:

<块引用>

他的容器 (com.example.pagercontainer.PagerContainer) 包装了 ViewPager 并在自身上调用 setClipChildren(false);,所以即使尽管 ViewPager 专注于一个选定页面,但坐标超出 ViewPager 边界的其他页面仍然可见,只要它们适合 PagerContainer.通过将 ViewPager 的大小设置为小于 PagerContainerViewPager 可以将其页面调整为该大小,从而为其他页面留出空间.但是,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 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.

这篇关于如何从 Gallery 迁移到 Horizo​​ntalScrollView &amp;浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆