[英]Nudge a paged recyclerview to hint at next page without switching
I'm using a horizontal recyclerview with a LinearLayoutManager and a PagerSnapHelper and each viewholder/page is fullscreen and snaps to the window so only one page is viewable once settled. 我正在使用带有LinearLayoutManager和PagerSnapHelper的水平recyclerview,每个视图持有者/页面都是全屏的,并且捕捉到窗口,因此一旦安放下来就只能看到一页。 Like most fullscreen swipeable tabs.
像大多数全屏可滑动标签一样。
When inserting a new page AFTER the current page, I want to temporarily show/hint at it's presence without snapping/scrolling to it ie so the user knows they opened a new page and it's there if they want to view it without forcing them to actually view it. 在当前页面之后插入新页面时,我想临时显示/提示它的存在而不会快速滚动/滚动到该页面,即,以便用户知道他们打开了一个新页面,并且如果要查看它而又没有强迫他们实际进入该页面查看它。
So it would be the same effect if you were to start dragging your finger a tiny bit to expose the next page before releasing and letting it snap back to the starting page. 因此,如果在释放之前开始稍稍拖动手指以露出下一页并将其弹回到起始页,将具有相同的效果。
How can I do this? 我怎样才能做到这一点? Thanks
谢谢
I haven't done it with a RecyclerView yet, but I managed to do something similar on a ViewPager. 我还没有用RecyclerView完成它,但是我设法在ViewPager上做了类似的事情。 Basically, you could use a ValueAnimator with a CycleInterpolator to scroll the RecyclerView each frame by a little bit and then back.
基本上,您可以将ValueAnimator与CycleInterpolator一起使用,以稍微滚动RecyclerView每帧,然后向后滚动。 Since it's scroll position is updated with each frame, I think this shouldn't collide with the snapping:
由于滚动位置随每一帧更新,因此我认为这不应与捕捉冲突:
val startX = recyclerView.getScrollX().toFloat()
val endX = startX + Utils.dpToPx(context, 100) // the amount you want to scroll in pixels
val animator = ValueAnimator.ofFloat(1f, 0f)
animator.cancel()
animator.interpolator = CycleInterpolator(0.5f)
animator.startDelay = 600
animator.duration = 600
animator.addUpdateListener { animation ->
val alpha = animation.animatedValue as Float
recyclerView.scrollTo((startX * alpha + (1f - alpha) * endX).toInt(), 0)
}
animator.start()
This works on a ViewPager and should just as well on a RecyclerView, since it has the same scrolling methods available... 这可以在ViewPager上使用,并且也可以在RecyclerView上使用,因为它具有相同的滚动方法...
recyclerView.smoothScrollBy(nudgeDistanceInPx, 0);
在PagerSnapHelper插入之前,它将平滑滚动以显示下一页并将其返回到其起始位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.