简体   繁体   English

微调页面回收视图以提示下一页而无需切换

[英]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.

相关问题 具有上一页和下一页边界的RecyclerView? - RecyclerView with previous and next page boundaries? 焦点切换到 FireTv 应用程序嵌套回收视图中的下一行 - Focus switching to next row in nested recyclerview in FireTv App 在 recyclerview 滚动时自动加载下一页的图像 - Automatically load images of next page on recyclerview scrolling 切换到下一页时,ViewPager跳到一半页面 - ViewPager jumps half the page when switching to next page 避免在ViewPager中切换页面,直到下一页上的内容准备就绪 - Avoid page switching in a ViewPager until the content on the next page is ready 在recyclerview之间切换或切换内容 - Switching between recyclerview or switching content 在Webview活动之间切换而无需重新加载页面 - switching between webview activity without reloading the page 在RecyclerView中切换项目视图类型 - Switching item viewtypes in RecyclerView 到达 RecyclerView 底部时从 API 接收下一页电影? - Receive next page of movies from API when bottom of RecyclerView is reached? 切换到Activity1(RecyclerView)切换到Activity2(RecyclerView) - Switching to Activity1 (RecyclerView) to Activity2 (RecyclerView)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM