gpt4 book ai didi

java - RecyclerView onScrolled 根本没有被触发

转载 作者:行者123 更新时间:2023-12-01 17:51:03 25 4
gpt4 key购买 nike

我计划创建一个分页滚动到底部的 RecyclerView。但 onScrolled 回调根本没有被触发:

    mBooksRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
Log.i("Dale", "scrolled");
}
});

mBooksRecyclerView.setNestedScrollingEnabled(false);

if (Utils.hasContent(books)) {
mBooksRecyclerView.setVisibility(View.VISIBLE);
BookCardViewAdapter adapter = new BookCardViewAdapter(this, books);

final GridLayoutManager gridLayoutManager = new GridLayoutManager(BooksActivity.this, 3);
mBooksRecyclerView.setLayoutManager(gridLayoutManager);
mBooksRecyclerView.setAdapter(adapter);

emptyView.setVisibility(View.GONE);
} else {
emptyView.setVisibility(View.VISIBLE);
mBooksRecyclerView.setVisibility(View.GONE);
}

我还尝试从 NestedScrollView 中删除 RecyclerView,但它仍然不起作用。

这是我的 XML 文件:

books_content.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="@dimen/books_category_height"
android:background="@color/gfs_blue">

<android.support.v7.widget.RecyclerView
android:id="@+id/categories_tab"
android:layout_width="match_parent"
android:layout_height="@dimen/books_category_height">

</android.support.v7.widget.RecyclerView>
</RelativeLayout>

<android.support.v7.widget.RecyclerView
android:id="@+id/sub_categories_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_marginTop="20dp">

</android.support.v7.widget.RecyclerView>

<android.support.v7.widget.RecyclerView
android:id="@+id/books_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/sub_categories_tab"
android:scrollbars="vertical" />
</RelativeLayout>

activity_books.gfs:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
tools:context=".activities.GFSBooksActivity">

<include
android:id="@+id/appbarlayout"
layout="@layout/appbarlayout"/>

<RelativeLayout
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_below="@id/appbarlayout"
android:background="@color/white"
android:visibility="gone">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No content found"
android:textColor="@color/gray"
android:textSize="20dp" />
</RelativeLayout>

<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/books_content"
android:layout_below="@+id/appbarlayout"/>
<!--<android.support.v4.widget.NestedScrollView-->

<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--app:layout_behavior="@string/appbar_scrolling_view_behavior">-->


<!--</android.support.v4.widget.NestedScrollView>-->

</RelativeLayout>


<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

最初,它位于 NestedScrollView 下,但由于有人提到,如果 RecyclerView 位于 NestedScrollView 内,则不会调用 onScroll或 ScrollView,我删除了 NestedScrollView

最佳答案

我重新启动了 Android Studio,它现在一直可以正常工作。但修复方法可能是删除 NestedScrollView 内的 RecyclerView。

关于java - RecyclerView onScrolled 根本没有被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50054960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com