我在nestedscrollview 中使用了2 個recyclerviews,但是在加載專案后,應用程式非常慢。它不是平滑滾動我試圖優化影像和視圖,但它根本沒有幫助。
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/md_grey_100"
android:clickable="true"
android:fillViewport="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_toolbar">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/rv_service_types"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:nestedScrollingEnabled="false" />
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/rv_stores"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:nestedScrollingEnabled="false" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
uj5u.com熱心網友回復:
如果 RecyclerView 中有大量專案,則應避免在 NestedScrollView 中使用 RecyclerView 如果專案包含來自在線的影像,則會導致很多滯后和延遲 使用不同的 RecyclerView,嘗試使用一個。在這種情況下,您應該為 Adapter 定義不同的視圖型別。
class YourAdapter(){
override fun getItemViewType(position: Int): Int {
return when (position) {
x-> xx
y-> yy
}
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
xx-> YourFirstViewHolder
yy ->YourSecondViewHolder
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/392344.html
上一篇:如何在XML中匯入Shape類
