java - 放入 NestedScrollView 时,列表页面 RecyclerView 无限滚动不起作用
问题描述
我已经采取了两个recyclerviews,因为我必须显示两个列表,其中一个是水平列表,另一个是具有无限滚动的垂直列表,对于滚动两个列表,我已将它们添加到nestedScrollView中,但垂直列表的无限滚动不起作用,有向下滚动时第一次加载项目后的分页逻辑然后调用api然后加载列表中的项目
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/llRecentlyBought"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/txtVRecentlyBought"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_grey_color"
android:padding="10dp"
android:text="@string/recently_bought"
android:textSize="@dimen/font_s_ize_levelone_signup" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerRecentlyBought"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:paddingStart="@dimen/padding_home_1"
android:paddingEnd="@dimen/padding_home_1"
android:scrollbars="none"
android:focusable="false"
android:focusableInTouchMode="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/products_in_gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/llRecentlyBought"
android:layout_alignParentStart="true"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:descendantFocusability="blocksDescendants"
android:fadingEdge="none"
android:paddingStart="@dimen/padding_home_1"
android:paddingEnd="@dimen/padding_home_1"
android:paddingBottom="@dimen/padding_home_1"
android:scrollbars="none"
android:focusable="false"
android:focusableInTouchMode="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
BaseAttacher mBaseAttacher = Mugen.with(productsInGridRecyclerView, new MugenCallbacks() {
@Override
public void onLoadMore() {
if (indexOfCurrentPage < TOTAL_PAGE_AVAILABLE) {
indexOfCurrentPage += 1;
// loadNextPage(indexOfCurrentPage);
if (isLastPage == false) {
loadNextPage(indexOfCurrentPage);
} else if (isLastPage == true) {
// Toast.makeText(getActivity(), "No more products", Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), getResources().getString(R.string.txt_no_product_found), Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean isLoading() {
return isLoading;
}
@Override
public boolean hasLoadedAllItems() {
return false;
}
}).
start();
mBaseAttacher.setLoadMoreEnabled(true);
mBaseAttacher.setLoadMoreOffset(2);
上面是垂直列表的baseattacher,当我向下滚动时它没有被调用,没有nestedscrollview它的工作帮助我在nestedscrollview中无限滚动列表
解决方案
不需要nestedscrollview 我刚刚将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到父布局中它可以工作!
推荐阅读
- .net-core - Visual Studio 在构建、重建和清理解决方案时使用什么 dotnet core cli 命令(或 msbuild 命令)?
- python - 更改 `jsons.dump(IPv4Adress(
))` 对跟随 `jsons.load` 是幂等的 - c - 在 NodeJS 中,如何读取 C 程序的输出?
- git - 给定一个文件,我可以检查 git repo 的历史记录中是否存在相同的文件?
- html - href 链接适用于一个项目,但不适用于另一个
- javascript - 如何用表中的前一个值增加表中的值?
- angular - 仅在应用启动时从 Firestore 获取数据,然后从那里分发
- css - 渲染高度和客户端高度不相同
- javascript - 表情符号 Facebook Messenger - Pesisten 菜单
- java - 为什么这些变量在这个泛型方法中有不同的类型?