NestedScrollView内的多个RecyclerView性能问题 [英] Multiple RecyclerView inside NestedScrollView Performance issue

查看:95
本文介绍了NestedScrollView内的多个RecyclerView性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NestedScrollView中添加多个RecyclerView时遇到性能问题.我在顶部显示两个水平,在底部显示垂直的RecyclerView.

I am facing performance issue while adding multiple RecyclerView inside NestedScrollView. I am displaying two horizontal on top and vertical RecyclerView on bottom.

我已在行下方添加

recyclerView.setNestedScrollingEnabled(false);

这可以正确显示所有列表,但真正的问题是我面临性能问题.

This is showing all list properly but real question is I am facing performance issue.

所有三个RecyclerView在大约5秒钟的所有响应到来之后显示.这也阻止了UI,因为它忙于RecyclerView的出现.

All three RecyclerView is showing after ~5 sec of all response come. This is also blocking UI as it busy for RecyclerView to appear.

XML

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/llTabs"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.turacomobile.gb.utils.CustomSFUIMediumTextView
            android:id="@+id/tvMyBrands"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="My Streamz (Brands)"
            android:textColor="@color/black" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvMyBrands"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="@dimen/dimen_5dp"
            android:paddingRight="@dimen/dimen_5dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <com.turacomobile.gb.utils.CustomSFUIMediumTextView
            android:id="@+id/tvRecommendedBrands"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="Recommended Streamz (Brands)"
            android:textAppearance="@style/TabLayoutTextStyleSearch"
            android:textColor="@color/black" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvRecommendedBrands"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="@dimen/dimen_5dp"
            android:paddingRight="@dimen/dimen_5dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <com.turacomobile.gb.utils.CustomSFUIMediumTextView
            android:id="@+id/tvSearchMyStreamz"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="Food from My Streamz Brands"
            android:textColor="@color/black" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

JAVA

    rvSearchStreamz = findViewById(R.id.my_recycler_view);
    rvMyBrands = findViewById(R.id.rvMyBrands);
    rvRecommendedBrands = findViewById(R.id.rvRecommendedBrands);

    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    rvSearchStreamz.setLayoutManager(llm);
    rvSearchStreamz.setNestedScrollingEnabled(false);
    rvSearchStreamz.setHasFixedSize(false);

    LinearLayoutManager llmMy = new LinearLayoutManager(this);
    llmMy.setOrientation(LinearLayoutManager.HORIZONTAL);
    rvMyBrands.setLayoutManager(llmMy);
    rvMyBrands.setNestedScrollingEnabled(false);
    rvMyBrands.setHasFixedSize(false);

    LinearLayoutManager llmRecommended = new LinearLayoutManager(this);
    llmRecommended.setOrientation(LinearLayoutManager.HORIZONTAL);
    rvRecommendedBrands.setLayoutManager(llmRecommended);
    rvRecommendedBrands.setNestedScrollingEnabled(false);
    rvRecommendedBrands.setHasFixedSize(false);

推荐答案

问题是NestedScrollView.您不应该在NestedScrollView中使用RecyclerView,因为RecyclerView不会回收NestedScrollView中的任何内容(您可以使用onCreateView和onBindView中的写入日志对其进行测试).更改容器布局类型,例如LinearLayout,RelativeLayout等.

The problem is NestedScrollView. You shouldn't use RecyclerView inside a NestedScrollView because RecyclerView don't recycle anything in a NestedScrollView(You can test it with write log in onCreateView and onBindView). Change the container layout type like LinearLayout, RelativeLayout etc.

这篇关于NestedScrollView内的多个RecyclerView性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆