【问题标题】:Can't scroll RecyclerView, when try to hide toolbar on scrolling尝试在滚动时隐藏工具栏时无法滚动 RecyclerView
【发布时间】:2018-02-13 21:19:51
【问题描述】:

我尝试在this tutorial
滚动列表隐藏工具栏 它在我的一个项目中工作,但是当我在另一个项目中尝试时,RecycleView 根本不滚动
而不是 RecycleView,工具栏是可滚动的
我的意思是我可以通过滚动工具栏来隐藏工具栏(上下滑动工具栏

app_bar_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="bearing.chavosh.com.bearingdemo.Activity.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/app_bar_background"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:background="#f5f5f5">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:theme="@style/ThemeOverlay.AppCompat.Light"
            app:popupTheme="@style/AppThemePopupOverlayLight">


            <bearing.chavosh.com.bearingdemo.Utility.MyTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ارسال موقعیت"
                android:textSize="17sp"
                android:textColor="#000000"
                android:layout_gravity="center"
                android:id="@+id/toolbar_title" />

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

        <View
            android:layout_width="match_parent"
            android:layout_height="0.25dp"
            android:id="@+id/viewShadow"
            android:background="#BBBBBB"/>

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

    <include layout="@layout/content_main"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />


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

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#f5f5f5"
    tools:context="bearing.chavosh.com.bearingdemo.Activity.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/llBarsList">

        <include layout="@layout/loads_list"
            android:layout_height="match_parent"
            android:layout_width="match_parent" />

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

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

上面源代码中包含的load_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<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:background="#f5f5f5"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:showIn="@layout/content_main">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f5f5f5"
        app:tabIndicatorColor="#0067A5"
        app:tabIndicatorHeight="2dp"
        app:tabMode="scrollable"
        app:tabGravity="center"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.25dp"
        android:layout_below="@+id/tabs"
        android:id="@+id/viewShadow"
        android:background="#BBBBBB"/>

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/viewShadow"
        android:id="@+id/vp_bars_list" />

</RelativeLayout>

我没有找到任何答案,我研究了一天
任何帮助,请

【问题讨论】:

  • 确保您使用相同的支持库版本
  • @MohammadRezaEram 感谢您的回答,但这对我没有帮助,我在两个项目中都使用相同的库
  • 你应该检查支持设计库
  • @MohammadRezaEram 两个项目中的所有库都相同:(

标签: android scroll android-recyclerview


【解决方案1】:

它不能正常工作,因为你通过包含布局搞砸了。您已将 load_list xml 包含在 content_main xml 中,但 loads_list xml 包含 TabLayout 一些 ViewViewPager 以及您通过 &lt;include layout="@layout/loads_list"/&gt; 放入 AppBarLayout 的所有内容。

AppBarLayout 可以包含TabLayoutViewPager 会搞砸。然后在app_main 中,您还有另一个AppBarLayout。所以把TabLayout直接放到app_mainxml下面Toolbar。并在CoordinatorLayout 中包含ViewPager。您可以摆脱其中一个不必要的 xml。

【讨论】:

  • 谢谢 :) 它可以工作,但我可以问为什么我使用 appBarLayout 时 recycleView 不滚动?我对此有点困惑
  • 您不能在 AppBarLayout 中使用 RecyclerView,我假设您正在替换 ViewPager 或在 Fragments 中加载,其中包含 RecyclerView
猜你喜欢
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多