我采取了两个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);
上面是垂直列表的基础附加组件,当我向下滚动时没有调用,没有nestedscrollview,它的工作有助于我在nestedscrollview中无限滚动列表
使用的库https://github.com/vinaysshenoy/mugen
最佳答案
不需要nestedscrollview
我刚刚将app:layout_behavior =“ @ string / appbar_scrolling_view_behavior”添加到父版式
有用 !!