我有2 recyclerView
,RecyclerView 1,有 layoutManagerapp:layoutManager="com.google.android.flexbox.FlexboxLayoutManager"
和另一个 RecyclerView 2,有app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
.
recyclerview
在另一个 recyclerView 上滚动时,第一项闪烁。当 RecyclerView 1 的项目数小于 6 或 7 时,它工作正常。
请查看视频链接以获取问题参考(0:18s - 0:46s):https ://drive.google.com/file/d/17_wa3vd5H7QKh0fgj6Sh310ZNlt2TeG1/view?usp=sharing
请在下面找到代码片段:
activity_personal_activities.xml
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_0"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="@+id/btnSave"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvHeaderTitle">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvConditionsSelected"
android:layout_width="@dimen/dp_0"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_12"
android:layout_marginBottom="@dimen/dp_20"
android:orientation="horizontal"
android:paddingStart="@dimen/dp_24"
android:paddingEnd="@dimen/dp_0"
app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="@dimen/dp_100"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:spanCount="2"
tools:itemCount="4"
tools:listitem="@layout/inflate_conditions_selected" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvConditions"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_0"
android:layout_marginTop="@dimen/dp_7"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvConditionsSelected"
tools:itemCount="5"
tools:listitem="@layout/inflate_conditions" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
设置适配器:
(bViewDataBinding?.rvConditionsSelected?.itemAnimator as? DefaultItemAnimator)?.supportsChangeAnimations = false
bViewDataBinding?.rvConditionsSelected?.adapter = adapter
RecyclerView 1 的 ScrollToPosition,在添加新项目时
bViewDataBinding?.rvConditionsSelected?.scrollToPosition(adapterList.size - 1)