我有一个 fragment ,其中包含一个带有 RecyclerView 的 SwipeRefreshLayour。
此 recyclerView 不显示过度滚动效果。我尝试了很多东西,比如使用这个:
android:isScrollContainer="true"
android:overScrollMode="always"
通过样式自定义颜色不起作用
fadingEdge, fadingEdgeLengh, requiresFadingEdge...
滑动刷新功能正常,显示如下:
我不明白:
最佳答案
我只是通过覆盖 SwipeRefreshLayout 并使用它而不是默认实现来解决它:
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
class SwipeRefreshLayoutWithRecyclerViewOverscroll : SwipeRefreshLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
override fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean =
(child.canScrollVertically(1) && super.onStartNestedScroll(child, target, nestedScrollAxes))
}
我正在使用一个 RecyclerView,它是一个线性垂直列表,child.canScrollVertically(1)
检查此列表当前是否位于最底部。如果它在列表的底部,onStartNestedScroll 返回 false,允许 RecyclerView 处理用户的上拉 Action ,从而显示过度滚动效果。
注意:这只显示底部边缘过度滚动,而不显示顶部边缘,因为我不想看到下拉刷新动画和顶部过度滚动边缘。
关于android - 过度滚动效果不会出现在我的 swiperefreshlayout 内的 recyclerview 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45927783/