madhura21
madhura21

Reputation: 43

Android :CollapsingToolbar is hidden after scrolling down

My layout includes Collapsing Toolbar and Tablayout with ViewPager If I scroll down and the scroll back up, CollapsingToolbar gets hidden .I have to drag the tablayout or swiperefresh down to make the CollapsingToolbar visible.The toolbar should be visible after I scroll up. Please Help. Here is my layout:

   <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"


    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <RelativeLayout
        android:id="@+id/main_frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/dashboard_app_bar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:stateListAnimator="@null"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:contentScrim="@color/light_red"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <RelativeLayout
                        android:id="@+id/relative_banner"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_collapseMode="parallax">

                        <android.support.v4.view.ViewPager
                            android:id="@+id/dashboard_img_banner_view_pager"
                            android:layout_width="match_parent"
                            android:layout_height="180dp"
                            android:layout_marginTop="60dp"
                            app:layout_collapseMode="parallax" />

                        <me.relex.circleindicator.CircleIndicator
                            android:id="@+id/dashboard_circular_indicator_one"
                            android:layout_width="match_parent"
                            android:layout_height="20dp"
                            android:layout_alignBottom="@+id/dashboard_img_banner_view_pager"
                            android:layout_marginBottom="10dp"
                            android:background="@android:color/transparent" />
                    </RelativeLayout>

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:background="@color/red_color"
                        app:contentInsetLeft="0dp"
                        app:contentInsetStart="0dp"
                        app:contentInsetStartWithNavigation="0dp"
                        app:layout_collapseMode="pin">

                        <RelativeLayout
                            android:id="@+id/rl_city_choice"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:clickable="true">

                            <ImageView
                                android:id="@+id/toolbar_img"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentLeft="true"
                                android:layout_alignParentStart="true"
                                android:src="@drawable/location" />

                            <org.offer_katta_ok.utils.CustomView.CustomRegularTextView
                                android:id="@+id/txt_city_name"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_centerVertical="true"
                                android:layout_marginLeft="2dp"
                                android:layout_marginStart="2dp"
                                android:layout_toEndOf="@+id/toolbar_img"
                                android:layout_toRightOf="@+id/toolbar_img"
                                android:text="@string/city"
                                android:textColor="#ffffff" />
                        </RelativeLayout>
                    </android.support.v7.widget.Toolbar>

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

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:behavior_overlapTop="0dp"
                app:layout_anchor="@+id/dashboard_app_bar"
                app:layout_anchorGravity="bottom"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/uncheck_radio_grey" />

                <android.support.design.widget.TabLayout
                    android:id="@+id/tab_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    app:behavior_overlapTop="0dp"
                    app:layout_collapseMode="none"
                    app:tabGravity="fill"
                    app:tabMode="fixed"
                    app:tabSelectedTextColor="@color/tab_text_color"
                    app:tabTextAppearance="@style/MyTabLayoutTextAppearance"
                    app:tabTextColor="@color/text_sub_content_color" />

                <android.support.v4.widget.SwipeRefreshLayout
                    android:id="@+id/refresh"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tab_layout">

                    <org.offer_katta_ok.home.pagerAdapter.CustomViewPager
                        android:id="@+id/pager"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tab_layout" />

                </android.support.v4.widget.SwipeRefreshLayout>

                <GridView
                    android:id="@+id/grid_category"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/tab_layout"
                    android:background="@color/white"
                    android:horizontalSpacing="2dp"
                    android:numColumns="2"
                    android:padding="10dp"
                    android:scrollbars="none"
                    android:verticalSpacing="2dp"
                    android:visibility="gone" />
            </RelativeLayout>

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

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/float_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="50dp"
            android:layout_marginEnd="5dp"
            android:layout_marginRight="5dp"
            android:scaleType="fitXY"
            android:src="@drawable/categories1"
            app:fabSize="mini"
            app:rippleColor="@android:color/transparent" />

    </RelativeLayout>
    <!-- The navigation drawer -->
    <ExpandableListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#77000000"
        android:cacheColorHint="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="2dp"
        android:groupIndicator="@null"
        android:listSelector="@color/red_color" />


</android.support.v4.widget.DrawerLayout>

I am facing the problem similar to the Gifs posted in this question:

Android: CollapsingToolbarLayout and SwipeRefreshLayout get stuck

Upvotes: 0

Views: 290

Answers (1)

fillobotto
fillobotto

Reputation: 3785

Without screenshots/gif it's difficult to understand but I'll try to. You need the scroll flag enterAlways so that the view will be visible as soon as you start scrolling up.

In the CollapsingToolbarLayout:

app:layout_scrollFlags="scroll|enterAwalys"

Also see documentation: https://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html

Upvotes: 1

Related Questions