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 &浏览器?
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
