android - 如何从 Gallery 迁移到 Horizo​​ntalScrollView & ViewPager?

标签 android gallery android-viewpager horizontalscrollview migrate

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

最佳答案

This gist from Dave Smith显示了一种使用 ViewPager 获得与 Gallery 非常相似的视觉结果的方法:

Gallery-style ViewPager

引用 my blog post on the topicViewPager 中一次显示多个页面:

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.

您可能还想筛选 this android-developers thread ,有人在较新的 Android 版本上指出了这个问题。您需要禁用硬件加速 due to a bug in ViewPager .

关于android - 如何从 Gallery 迁移到 Horizo​​ntalScrollView & ViewPager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12239886/

相关文章:

java - Android:将数据从 ViewPager2 和 TabLayout 管理的 fragment 发送到包含的 Activity

android - 重新创建 fragment - 查看寻呼机 - FragmentPagerAdapter

java - 在 POS/ESC 热敏打印机 Android 上打印图像

java - 调用 getJSONObject 时出现 JSON 异常

java - fragment 和 ListView

java - 以编程方式从 Firebase 数据库获取子名称

jquery 在单击的实例之后查找下一个图像

android - 从 Android 手机获取图像和视频到自定义图库

android - SecurityException 从 Android 库中读取图片

android - ViewPager 不显示第一个 fragment ,如果它的内容是动态加载的