gpt4 book ai didi

android-recyclerview - FlexboxLayoutManager 项目在滚动另一个 Recycler View 时闪烁

转载 作者:行者123 更新时间:2023-12-04 08:08:40 30 4
gpt4 key购买 nike

我有 2 recyclerView , RecyclerView 1, layoutManager with app: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 的 ScrollToPosition 1,添加新项目
bViewDataBinding?.rvConditionsSelected?.scrollToPosition(adapterList.size - 1)

最佳答案

我找到了闪烁问题的根本原因,问题出在第一个 recyclerView 高度上。所以我通过最初添加固定高度来解决这个问题。如果您在我的查询中看到,recyclerView 高度为 android:layout_height="@dimen/dp_0" & app:layout_constraintHeight_max="@dimen/dp_100"这导致 FlaxBoxLayoutManager recyclerView 闪烁。

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvConditionsSelected"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_36"
android:layout_marginTop="@dimen/dp_12"
android:orientation="horizontal"
app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager"
android:paddingStart="@dimen/dp_24"
android:paddingEnd="@dimen/dp_0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/cvSearch"
tools:itemCount="4"
tools:listitem="@layout/inflate_conditions_selected" />
所以,我正在以编程方式更改 recyclerView 的高度
override fun updateRecyclerViewHeight() {
val flexSize = (bViewDataBinding?.rvConditionsSelected?.layoutManager as? FlexboxLayoutManager)?.flexLinesInternal?.size
?: return
when (flexSize) {
3 -> changeRecyclerViewHeight(SizeUtils.dp2px(this,100F))
2 -> changeRecyclerViewHeight(SizeUtils.dp2px(this,72F))
1 -> changeRecyclerViewHeight(SizeUtils.dp2px(this,36F))
}
}

override fun changeRecyclerViewHeight(height: Int) {
val params = bViewDataBinding?.rvConditionsSelected?.layoutParams
params?.height = height
bViewDataBinding?.rvConditionsSelected?.layoutParams = params
}

关于android-recyclerview - FlexboxLayoutManager 项目在滚动另一个 Recycler View 时闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66089310/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com