以编程方式滚动 ViewPager,少量滚动 [英] Scrolling a ViewPager programmatically, by a small amount

查看:31
本文介绍了以编程方式滚动 ViewPager,少量滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有效地并排两个活动,允许用户从一个滚动到另一个,然后返回.我认为 ViewPager 可能是处理此问题的最佳方式,但我愿意接受建议.

I have the requirement for what is effectively two activities side by side, allowing the user to scroll from one to the other, and back. I've decided that ViewPager is probably the best way to handle this, but am open to suggestions.

当活动加载时,会显示左侧视图.我想向用户表明另一个视图存在,只需将其向左和向后滚动少量(类似于现在显示滑动抽屉菜单存在的常见方式).

When the activity loads, the left hand view is displayed. I want to indicate to the user that the other view exists, by just scrolling it a small amount to the left and back again (similar to the way it's now common to show that a sliding drawer menu exists).

我已经尝试了很多方法,但还没有找到一种方法可以让两个视图平滑地滚动在一起.解释需求的另一种方式是说我想以编程方式假装用户短暂地轻弹页面.

I've tried a number of things but have yet failed to find a method where both the views scroll smoothly together. Another way of interpretting the requirement is saying I want to programmatically fake a user flicking the page briefly.

推荐答案

尝试调用方法 fakeDragBy(float)!根据文档,您需要先调用 beginFakeDrag() 启动它,然后调用 endFakeDrag().这将保持 ViewPagers 默认的捕捉行为,因此一旦您显示另一个屏幕在那里,您就不必为过渡设置动画,只需调用 endFakeDrag 并且 ViewPager 将正确地捕捉回最后一个屏幕(只要您还没有把它拖过中途标记).

Try calling the method fakeDragBy(float)! According to the documentation you need to first call beginFakeDrag() to initiate it and then call endFakeDrag(). This will mantain the ViewPagers default snapping behavior, so once you've revealed the other screen is there you don't have to animate the transition back, simply call endFakeDrag and the ViewPager will correctly snap back to the last screen (As long as you haven't dragged it past the half-way mark).

这篇关于以编程方式滚动 ViewPager,少量滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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