diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt index 1c82425b0..a7299f5e6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt @@ -150,8 +150,7 @@ class FastScrollRecyclerView : RecyclerView { super.onAttachedToWindow() mFastScroller.attachRecyclerView(this) val parent = parent - if (parent is ViewGroup) { - parent.removeView(mFastScroller) + if (parent is ViewGroup && parent.indexOfChild(mFastScroller) == -1) { parent.addView(mFastScroller) mFastScroller.setLayoutParams(parent) } diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt index a8372689e..857035158 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt @@ -152,12 +152,10 @@ class FastScroller : LinearLayout { fun attachRecyclerView(recyclerView: RecyclerView) { mRecyclerView = recyclerView - if (mRecyclerView != null) { - mRecyclerView!!.addOnScrollListener(mScrollListener) - post { - // set initial positions for bubble and handle - setViewPositions(getScrollProportion(mRecyclerView)) - } + mRecyclerView!!.addOnScrollListener(mScrollListener) + post { + // set initial positions for bubble and handle + setViewPositions(getScrollProportion(mRecyclerView)) } }