我正在使用带有 LinearLayoutManager 和 PagerSnapHelper 的水平回收器 View ,并且每个查看器/页面都是全屏的并捕捉到窗口,因此一旦确定就只能查看一个页面。与大多数全屏可滑动标签一样。
在当前页面之后插入一个新页面时,我想暂时显示/提示它的存在而无需捕捉/滚动到它,即这样用户就知道他们打开了一个新页面,如果他们想查看它而无需强制他们实际查看它。
因此,如果您开始稍微拖动手指以显示下一页,然后松开手指并让它弹回到起始页,效果会是一样的。
我该怎么做?谢谢
最佳答案
我还没有用 RecyclerView 完成它,但我设法在 ViewPager 上做了类似的事情。基本上,您可以使用带有 CycleInterpolator 的 ValueAnimator 来滚动 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,因为它具有相同的可用滚动方法...
关于android - 轻推分页回收 View 以在不切换的情况下提示下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56585699/