My app contains a fragment with toolbar , linear layout and Tabllayout. I have enabled the scrollflags to the toolbar. Now when i try scrolling in the recyclerview in the tablayout the toolbar is not hinding. When i Push the tablayout manually it started moving and able to hide or show. Below are the layouts which I am using. What is wrong here.
Main layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/app">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:background="@color/textcolor"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<Button
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:background="@drawable/backblack" />
</android.support.v7.widget.Toolbar>
<LinearLayout
android:id="@+id/layloc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:orientation="horizontal"
android:weightSum="1"
android:padding="5dp"
android:background="@drawable/border"
android:visibility="gone">
<TextView
android:id="@+id/locationname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableStart="@drawable/location"
android:drawableLeft="@drawable/location"
android:drawablePadding="3dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:textColor="@color/cblack"
android:text="fetching current location"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium.Inverse"/>
<TextView
android:id="@+id/change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Change"
android:drawablePadding="3dp"
android:textColor="@color/cblack"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layloc"
android:background="@color/textcolor"
app:tabTextColor="@color/black"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabIndicatorHeight="2dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Fragment layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/textcolor"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/mainexplore">
<android.support.v7.widget.RecyclerView
android:id="@+id/lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/list_divider"
android:dividerHeight="1px"
android:scrollbars="none"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<TextView
android:id="@+id/emptyElement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/nofoodfound"
android:textColor="@color/button"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
I have tried with the different scroll flags but the problem is same. I have seen examples and some issues similar to this in the SO but none of them answers my query. The toolbar can be able to hide but need to push manually. What is the wrong with the layouts. What is missing in this layouts.
You need to remove button view from appBarLayout. Check mine.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator_layout"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:elevation="5dp"
android:theme="@style/ToolbarTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:titleTextAppearance="@style/Toolbar.TitleText"
/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/textcolor"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways">
<Button
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/backblack" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
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.