How to migrate from Gallery to HorizontalScrollView amp; ViewPager?(如何从 Gallery 迁移到 HorizontalScrollView amp;浏览器?)
问题描述
我需要在 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 theViewPagerand callssetClipChildren(false);on itself, so even though theViewPageris focused on one selected page, other pages that have coordinates beyond theViewPagerbounds are still visible, so long as they fit within thePagerContainer. By sizing theViewPagerto be smaller than thePagerContainer, theViewPagercan 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, asViewPagerwill 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 &浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Gallery 迁移到 HorizontalScrollView &浏览器?
基础教程推荐
- LocationClient 与 LocationManager 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
