循环器视图在嵌套滚动视图中不平滑



我在片段视图中有一个回收器视图和一个横幅广告,当我向下滚动时,我想用回收器视图滚动广告。我正在使用嵌套滚动和广告滚动是很好的开始。但当我向下滚动它时,更多的数据来自服务器,它就不能保持平稳,有时会停止。我试过每一种溶胶,但都不适合我。

这是一些代码。

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嵌套滚动错误

类似

recyclerViewSignup.setNestedScrollingEnabled(false);

最新更新