简体   繁体   English

无法滚动 RecyclerView,尝试在滚动时隐藏工具栏

[英]Can't scroll RecyclerView, when try to hide toolbar on scrolling

I try to hide toolbar on scrolling list from this tutorial我尝试在教程中隐藏滚动列表上的工具栏
it works in one of my project, but when i try that in another project RecycleView doesn't scroll at all适用于我的一个项目,但是当我在另一个项目中尝试时,RecycleView根本不滚动
And instead of RecycleView the toolbar is scrollable !而不是 RecycleView工具栏是可滚动的
I mean that I can hide toolbar by scrolling toolbar ( slide down and up the toolbar )我的意思是我可以通过滚动工具栏来隐藏工具栏(向下和向上滑动工具栏

app_bar_main.xml: 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: 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 that include in above source code: 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>

I didn't find any answer and I was working on it for one day我没有找到任何答案,我正在研究一天
any help , please任何帮助,请

Its not working properly because you mess things up by including layouts.它无法正常工作,因为您通过包含布局将事情搞砸了。 You have included load_list xml in content_main xml but loads_list xml contains TabLayout some View and ViewPager and all of that you put inside AppBarLayout by <include layout="@layout/loads_list"/> .您已包括load_list XML在content_main XML,但loads_list XML包含TabLayout一些ViewViewPager和所有的,你把里面的AppBarLayout通过<include layout="@layout/loads_list"/>

AppBarLayout can contain TabLayout but ViewPager will mess things up. AppBarLayout可以包含TabLayoutViewPager会把事情搞砸。 And then inside app_main you have another AppBarLayout .然后在app_main里面你有另一个AppBarLayout So put TabLayout directly into app_main xml below Toolbar .所以把TabLayout直接进入app_main下面的XML Toolbar And include ViewPager below them inside CoordinatorLayout .并将ViewPager包含在它们下方的CoordinatorLayout You can get rid of one of those xml its unnecessary.您可以摆脱那些不必要的 xml 之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebView滚动时无法隐藏工具栏 - can`t hide toolbar when webview scrolling 当我向上滚动 RecyclerView 时,工具栏和 TabLayout 不会隐藏 - Toolbar and TabLayout don't hide when I scroll the RecyclerView up 工具栏不会隐藏在DrawerLayout中的Scrolling recyclerview上 - Toolbar doesn't hide on Scrolling recyclerview in DrawerLayout 滚动ListView时无法隐藏带有动画的工具栏 - Can't to hide ToolBar with animation when scroll ListView 滚动recyclerview时如何在状态栏下完全隐藏工具栏 - How to hide toolbar fully under status bar when scrolling recyclerview 使用滚动RecyclerView时如何在ViewPager中隐藏工具栏? - How to hide the toolbar in a ViewPager when using Scrolling RecyclerView? 滚动时工具栏不会隐藏 - Toolbar doesn't hide when scrolling 当使用协调器布局滚动我的recyclerview时,如何提供自动隐藏/显示工具栏? - How can I provide auto-hide/show toolbar, when scroll my recyclerview with coordinator layout? 在NestedScrollView中使用recyclerView时如何隐藏滚动条上的工具栏 - how to hide toolbar on scroll when using recyclerView inside NestedScrollView 在片段内而不是活动内使用recyclerview时,在滚动条上隐藏工具栏 - Hide toolbar on scroll when the using a recyclerview inside a Fragment instead of an Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM