- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我计划创建一个分页滚动到底部的 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/
使用scrolltop,我使用if条件将滚动分为5部分。在第二部分中,我给出了scrolltop值从600到700px的视频。如果我再次滚动,视频会在该位置播放多次。但我希望视频必须如果我在该值内任意
我想做的就是在页面加载时触发一个函数。 似乎我的代码中有一个错误,但我无法弄清楚...我想我还是菜鸟... Hi, function myFunction () { docume
所以我有一个元素,我希望能够使用鼠标上的滚轮放大和缩小。我认为解决这个问题的一个好方法是这样的: JavaScript: var container = document.getElementById
我想在用户滚动网页时加载更多内容。我尝试使用 onScroll 事件 javascript 被多次调用 jQuery .scroll() 方法也被多次调用。 我该如何处理这个问题?是浏览器问题吗? 注
这是简化的 html: function handle() { console.log("fired"); };
我一直在研究 horizontal website本周并从这里的社区收到了很多建议和有用的代码(谢谢!)。 我的 JS 技能非常不稳定,但我正在更好地掌握它,我的 CodePen展示了我刚才所拥有的,
我使用此代码在滚动时获取页面中元素的偏移量,但滚动函数仅执行一次并提醒 viewportWidth,然后它停止在“off”变量处 这是原始脚本中的一个简单示例,它不仅仅是将 #menuIcon 设置为
// Schließen Button Hauptnavigation $('button#collapse-button').click(function () { $('n
我知道我只能调用一次window.onscroll = function(){},因为多次调用它可能会导致它们相互覆盖。这就是为什么我问:是否可以将函数调用“推送”到 window.onscroll?
实际上我见过一个网站,在滚动时自动加载新页面并将其附加到旧页面。 不仅是页面,URL 也会在滚动时发生变化。 我完全不知道如何实现这个。这是我看过的网站 matt 。这里只要向下滚动,就会有一个无限滚
我试图在屏幕上显示相应内容期间使菜单项显示为粗体,然后在该内容滚动过去后恢复正常。 我已经尝试了很多方法来做到这一点,但它似乎并没有奏效。我可以在适当的时候让它变粗,但是当我尝试添加属性让它恢复正常时
我有一个脚本,它在文档正文上运行 onmousemove 和 onscroll 的 addEventListener 以获取光标位置。 onmousemove 事件工作正常(客户端+滚动),但是当发生
是否可以检测用户何时在 facebook Canvas 应用程序上滚动(在 iframe 中)。因此,当用户在页面上向下滚动时,我可以执行操作。 最佳答案 您可以使用 jQuery API 并尝试他们
我有一个在滚动时收缩的横幅和它下面的一些内容,我怎样才能让内容在移动前在横幅上停留几秒钟?我尝试使用 jQuery 插件 stickem,但它似乎不起作用。 JS: $(document).scrol
我有一个 JavaScript 函数,它在窗口滚动到特定点时执行不同的条件语句。 (当窗口滚动到新的部分/行时或多或少地改变了我的导航链接的样式) // variables used var pLin
hi on scroll active class 未添加到li on click on a 工作正常请看一次。 $('nav a').on('click', function() {
我是 javascript 的新手,我试图在滚动 div id="container"时触发 div id="foo",以便在滚动 id“container”时说“IM AWESOME” .我什至给了
当用户滚动超过 25 像素时,我试图将 class 添加到 id。我不确定为什么,但我放学后该功能没有启动。任何关于为什么的帮助将不胜感激。这是我的代码: window.onscoll = funct
我需要显示水平 ListView 项目的无限滚动(意味着需要重复项目)例如 a,b,c,d,e,f,a,b,c,d,e,f,a,b,.... 粗体是屏幕上可见的项目 过程是在到达最后一个列表项后重复列
我想在发生滚动事件时实现onScroll。但是我不明白如何使用我通过 onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
我是一名优秀的程序员,十分优秀!