【问题标题】:how to show a bounce effect when scrolling is disabled in a recyclerview?在回收站视图中禁用滚动时如何显示弹跳效果?
【发布时间】:2019-05-23 05:24:35
【问题描述】:

我有一个水平滚动的recyclerview。当用户单击某个项目时,我已禁用滚动 recyclerview。现在,如果用户在列表锁定时尝试滚动列表,我想显示他/她无法进一步滚动的反弹效果。

例如:

我有一个10 items 列表,用户点击了5th item。现在滚动已锁定,当用户尝试滚动时,我想显示用户无法滚动的反弹效果。

这是我的自定义LinearLayoutManager

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.util.AttributeSet


class CustomLinearLayoutManager : LinearLayoutManager {
  private var isScrollEnabled = true

  constructor(context: Context) : super(context)

  constructor(context: Context, orientation: Int, reverseLayout: Boolean) : super(context, orientation, reverseLayout)

  constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)


  fun setScrollEnabled(flag: Boolean) {
    this.isScrollEnabled = flag
  }

  override fun canScrollHorizontally(): Boolean {
    //Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
    return isScrollEnabled && super.canScrollHorizontally()
  }
}

这是我的 recyclerview 启用/禁用滚动代码:

val layoutManager = CustomLinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
binding.recyclerView.layoutManager = layoutManager
layoutManager.setScrollEnabled(false)

【问题讨论】:

    标签: android android-recyclerview linearlayoutmanager


    【解决方案1】:

    您可以使用 bouncy recyclerview 来实现此功能并使用下面的链接来使用它 BoucncyRecyclerview 或者您可以使用 OverScroll effect of recyclerview 使用 recyclerview 的 Overscroll 效果

    【讨论】:

    • 但用户也可以位于列表的中间。当用户到达 recyclerview 列表的末尾或开头时,这将起作用。
    猜你喜欢
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    相关资源
    最近更新 更多