yuan tian
yuan tian

Reputation: 41

Toolbar can't auto-hide when viewpager's list scrolling down

I use CoordinatorLayout and AppBarLayout to try get the effect that the toolbar hides automatically as the ListView contained in the viewPager's Fragment scrolling down,but it doesn't work!The Toolbar never hide as I wish!Any of your suggestion will be appreciated! xml code:

 <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:orientation = "vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <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"
                />
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/md_primary_green"
                app:tabGravity="fill"
                app:tabMode="fixed"
                app:tabSelectedTextColor="#ff0000"
                app:tabTextColor="@color/md_text"/>
        </android.support.design.widget.AppBarLayout>


        <!--<LinearLayout-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="match_parent"-->
            <!--android:orientation="vertical"-->
            <!--android:scrollbars="none"-->
             <!-->-->

            <android.support.v4.view.ViewPager
                android:id="@+id/viewgroup"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:layout_width="match_parent">
            </android.support.v4.view.ViewPager>
        <!--</LinearLayout>-->
    </android.support.design.widget.CoordinatorLayout>

Upvotes: 0

Views: 335

Answers (1)

yuan tian
yuan tian

Reputation: 41

The reason is the AppBarLayout cannot be fully compatible with old controls.When I replaced the ListView with RecycleView,it works well.

Upvotes: 2

Related Questions