回收器视图在嵌套滚动视图中不平滑

时间:2018-08-03 11:25:57

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

我在片段视图中有一个回收站视图和一个横幅广告,当我向下滚动时,我想用回收者视图来滚动广告。  我正在使用嵌套滚动,并且广告最初滚动良好。但是当我向下滚动它并且更多的数据来自服务器时,它就不会保持平稳并停止一些时间。    我已经尝试了所有堆栈上的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"/>

2 个答案:

答案 0 :(得分:0)

请设置此

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

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

答案 1 :(得分:0)

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

  

喜欢

public class BaseApplication extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
    }
}
相关问题