簡體   English   中英

回收器視圖在嵌套滾動視圖中不平滑

[英]Recycler view not smooth inside nested scroll view

我在片段視圖中有一個回收站視圖和一個橫幅廣告,當我向下滾動時,我想用回收站視圖來滾動廣告。 我正在使用嵌套滾動,並且廣告最初滾動良好。 但是當我向下滾動它並且更多的數據來自服務器時,它就不會保持平穩並停止一些時間。 我已經嘗試了所有堆棧上的sol,但沒有任何工作適合我。

這是一些代碼。

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"/>

請設定這個

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

            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });

您可以將RecyclerView嵌套滾動設置為false

喜歡

recyclerViewSignup.setNestedScrollingEnabled(false);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM