繁体   English   中英

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

[英]Nudge a paged recyclerview to hint at next page without switching

我正在使用带有LinearLayoutManager和PagerSnapHelper的水平recyclerview,每个视图持有者/页面都是全屏的,并且捕捉到窗口,因此一旦安放下来就只能看到一页。 像大多数全屏可滑动标签一样。

在当前页面之后插入新页面时,我想临时显示/提示它的存在而不会快速滚动/滚动到该页面,即,以便用户知道他们打开了一个新页面,并且如果要查看它而又没有强迫他们实际进入该页面查看它。

因此,如果在释放之前开始稍稍拖动手指以露出下一页并将其弹回到起始页,将具有相同的效果。

我怎样才能做到这一点? 谢谢

我还没有用RecyclerView完成它,但是我设法在ViewPager上做了类似的事情。 基本上,您可以将ValueAnimator与CycleInterpolator一起使用,以稍微滚动RecyclerView每帧,然后向后滚动。 由于滚动位置随每一帧更新,因此我认为这不应与捕捉冲突:

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()

这可以在ViewPager上使用,并且也可以在RecyclerView上使用,因为它具有相同的滚动方法...

recyclerView.smoothScrollBy(nudgeDistanceInPx, 0);

在PagerSnapHelper插入之前,它将平滑滚动以显示下一页并将其返回到其起始位置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM