当前位置: 首页 > 知识库问答 >
问题:

工具栏不响应滚动事件

杨鸿畅
2023-03-14

我想在ListView滚动时隐藏/显示工具栏。我有包含工具栏的CorrdinatorLayout。我将app:layout_scrollflags=“scrollenterAlways”属性添加到工具栏中。然后,我在content_min布局中使用relationvelayout使用app:layout_behavior=“@string/appbar_scrolling_view_Behavior”属性创建了Listview。我在CoordinatorLayout-Toolbar中包含了content_main布局,该布局不响应ListView上的滚动事件。此功能是否只适用于RecycerView,而不适用于ListView?

<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.era.www.onmovie.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>


<include layout="@layout/content_main" />

content_main布局

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.era.www.onmovie.MainActivity"
tools:showIn="@layout/activity_main">


<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<TextView
    android:id="@+id/empty_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />

<ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />

共有1个答案

郎增
2023-03-14

滚动行为适用于RecycerView,但不适用于ListView。这是因为滚动行为需要一个实现NestedScrollingChild接口的滚动组件。此接口由RecycerView实现,而不是由ListView实现。

我的建议是将ListView适配器转换为RecycerView适配器,并使用RecycerView

应该有一些方法可以将ListView放入NestedScrollView中,从而提供滚动行为。我不建议这样做,但是如果进行搜索,您可以找到一些解决方案,将ListView包装在NestedScrollView中,并使工具栏滚动。

 类似资料:
  • 我正在尝试在我的android应用程序中实现折叠工具栏。我可以按我希望的方式显示工具栏,但滚动时它不会塌陷。 我正在使用以下代码 activity.xml main_toolbar.xml 下面是屏幕的外观

  • 当想下滚动页面的时候,Framework7可以让导航栏和工具栏自动隐藏。 如果你想全局启用这个功能,你只需要在 应用初始化 时候设置这几个参数:hideNavbarOnPageScroll, hideToolbarOnPageScroll, hideTabbarOnPageScroll 和 showBarsOnPageScrollEnd: 如果你只想在某些特定页面打开自动隐藏的功能,你可以通过添加

  • 当我做快速挺举时,我有一个CollapsingToolbarLayout的问题。隐藏appBar也会发生同样的事情 我需要工具栏隐藏在滚动和折叠工具栏折叠。当滚动不是很快时,它工作得很好。 但是当它很快的时候——似乎appBar在那之后就崩溃并扩展了。但它没有扩展回来。 请看视频。 折叠工具栏布局 应用程序栏 似乎这个答案是我需要的,但它不起作用。 我的折叠工具栏布局的 xml :

  • 我有一个活动,主机2个片段,我目前使用协调器布局在两个片段与appbarlayout和工具栏布局,我已经设置它这样滚动工具栏屏幕与我的回收视图。这一直导致我的布局问题,因为我已经在这里发布,所以我希望改变我的方法。如果我可以,该活动将在协调器布局中宿主工具栏/应用程序栏布局。

  • 本文向大家介绍jQuery响应滚动条事件功能示例,包括了jQuery响应滚动条事件功能示例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了jQuery响应滚动条事件功能。分享给大家供大家参考,具体如下: 更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery切换特效与技巧总结》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总

  • 我正在我的应用程序中实现折叠工具栏,它应该没问题,但栏不受限制..不动不做任何!!! 这是我的布局. xml 这是我的活动 请告诉我为什么,提前谢谢! 更新:我已经解决了NestedScrollView的问题,我做了如下操作: