在加载大量数据时,NestedScrollView中的RecyclerView需要花费太多时间

时间:2018-01-03 08:06:42

标签: android android-recyclerview android-nestedscrollview

NestedScrollView中的RecyclerView在加载大量数据时会冻结Activity。使用ScrollView加载速度要快得多,但在这种情况下滚动会受到影响。 我尝试设置像setAutoMeasure和setNestedScrollingEnabled这样的属性没有帮助。 有什么建议吗?

4 个答案:

答案 0 :(得分:0)

您可以加入app:layout_behavior="@string/appbar_scrolling_view_behavior"

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

或禁用回收站视图的嵌套滚动行为。

recyclerView.setNestedScrollingEnabled(false);

答案 1 :(得分:0)

在滚动视图中使用自定义列表视图而不是Recycler视图...

Check this Answer

自定义列表视图

[root@74dfbb491710 wd]# go run ssl.go https://google.com
&{0xc4200ce000 <nil> <nil> 0s}
[root@74dfbb491710 wd]# go run ssl.go https://jobs-eu.hudson.com
&{0xc4200e4000 <nil> <nil> 0s}
Something bad happened:  Get https://jobs-eu.hudson.com: tls: received unexpected handshake message of type *tls.serverKeyExchangeMsg when waiting for *tls.certificateStatusMsg

答案 2 :(得分:0)

这有助于提高回收者视图滚动的速度。

SpeedyLinearLayoutManager linearLayoutManager = new SpeedyLinearLayoutManager(MainActivity.this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

myRecyclerView.setLayoutManager(linearLayoutManager);

SpeedyLinearLayoutManager.class

 public class SpeedyLinearLayoutManager extends LinearLayoutManager {

        private static final float MILLISECONDS_PER_INCH = 2f; //default is 25f (bigger = slower)

        public SpeedyLinearLayoutManager(Context context) {
            super(context);
        }

        public SpeedyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
        }

        public SpeedyLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }

        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

            final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
                }

                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
                }
            };

            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        }
    }

答案 3 :(得分:0)

据我所知,NestedScrollViews内部不支持回收视图,因此建议尝试更改布局。