【问题标题】:Recycler view not smooth inside nested scroll view回收器视图在嵌套滚动视图中不平滑
【发布时间】:2018-08-03 11:25:57
【问题描述】:

我在片段视图中有一个回收器视图和一个横幅广告,当我向下滚动时,我想用回收器视图滚动广告。 我正在使用嵌套滚动,并且广告最初滚动良好。但是当我向下滚动它并且更多数据来自服务器时,它不会保持平滑并且有时会停止。 我已经尝试了堆栈上的每一个溶胶,但对我没有任何帮助。

这是一些代码。

fragment_all.xml:

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:id="@+id/nestedScroll"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none"
        >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:visibility="gone"
            android:focusableInTouchMode="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/news_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:nestedScrollingEnabled="false"
             />
    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

fragment_all.java:

                          nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if(v.getChildAt(v.getChildCount() - 1) != null) {
                if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
                        scrollY > oldScrollY) {

                    visibleItemCount = layoutManager.getChildCount();
                    totalItemCount = layoutManager.getItemCount();
                    pastVisibleItems = ((LinearLayoutManager) recyclerView.getLayoutManager())
                            .findFirstVisibleItemPosition();

                        if ((visibleItemCount + pastVisibleItems) >=totalItemCount) {

                            if (!loadingInside) {
                            loadingInside = true;
                            postNo = postNo + 15;
                            getDataFromUrl(postNo);
                        }
                        }
                }
                }
            }
           });

注意:我尝试过类似的解决方案:

<app:layout_behavior="@string/appbar_scrolling_view_behavior"
                      android:nestedScrollingEnabled="false"/>

【问题讨论】:

标签: android scroll android-recyclerview smooth-scrolling android-nestedscrollview


【解决方案1】:

您可以将 RecyclerView 嵌套滚动设置为 false

喜欢

recyclerViewSignup.setNestedScrollingEnabled(false);

【讨论】:

    【解决方案2】:

    请设置这个

    rec_view_notification.setLayoutManager(new LinearLayoutManager(getContext(), 
                      LinearLayoutManager.VERTICAL, false) {
                @Override
                public boolean canScrollHorizontally() {
                    return false;
                }
    
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
    

    【讨论】:

    • 我在上面提到过我已经尝试过这个解决方案,但它不起作用。
    • 你尝试过务实的设置吗?
    • 哦..你在应用这个方法的时候有注释其他代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多