具有上一页和下一页边界的 ViewPager [英] ViewPager with previous and next page boundaries

查看:33
本文介绍了具有上一页和下一页边界的 ViewPager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个包含多个页面的视图.我希望上一页和下一页的边缘如下所示,并实现 2 指滑动以在页面之间切换.

I'm designing a view with multiple pages. I want edges of previous and next pages to be show like below and implement a 2 finger swipe to switch between pages.

我尝试使用带有负页边距的 ViewPager 作为建议 此处 但这仅显示屏幕上的一个边缘,而不是同时显示.

I tried using ViewPager with negative page margin as suggested here but that only shows one of the edges on the screen, not both simultaneously.

或者,有什么方法可以将我的视图的一部分定位在屏幕外,然后为其设置动画,使其具有 ViewPager 类型的效果.

Alternatively, is there any way i can position part of my view outside screen and then animate it giving it a ViewPager type effect.

我该怎么办?谢谢!

推荐答案

引用自 关于这个主题的博文:

第三种方法来自 Dave Smith,他是广受好评的 Android Recipes 一书的合著者.他走向了一个非常不同的方向,使用了一个自定义容器,该容器禁止儿童一次显示多个页面.

The third approach comes from Dave Smith, co-author of the well-regarded book Android Recipes. He went in a very different direction, using a custom container that disabled children clipping to show more than one page at a time.

他的发布的示例代码展示了整个过程.他的容器 (com.example.pagercontainer.PagerContainer) 包装了 ViewPager 并调用 setClipChildren(false); 自身,所以即使 ViewPager 专注于一个选定的页面,坐标超出 ViewPager 边界的其他页面仍然可见,只要它们适合 PagerContainer.通过将 ViewPager 的大小设置为小于 PagerContainerViewPager 可以将其页面调整为该大小,从而为其他页面留出可见的空间.不过,PagerContainer 需要对触摸事件有所帮助,因为 ViewPager 只会在其自身可见的边界上处理滑动事件,而忽略侧面可见的任何页面.

His published sample code shows the whole thing in action. 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.

这篇关于具有上一页和下一页边界的 ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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