简体   繁体   中英

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
And instead of RecycleView the toolbar is scrollable !
I mean that I can hide toolbar by scrolling toolbar ( slide down and up the toolbar )

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

<?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"/> .

AppBarLayout can contain TabLayout but ViewPager will mess things up. And then inside app_main you have another AppBarLayout . So put TabLayout directly into app_main xml below Toolbar . And include ViewPager below them inside CoordinatorLayout . You can get rid of one of those xml its unnecessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM