Oguz Ozcan
Oguz Ozcan

Reputation: 1714

SmoothAppBarLayout collapsed toolbar height is bigger than intended

I recently changed my AppBarLayout with SmoothAppBarLayout

It is smoother and faster so i am happy with the result. But this changed my toolbar height somehow and i couldn't yet fix it.

Collapsed ToolBar's height should be 'actionBarSize' but it is bigger than that.

It is not about toolbar title, disabling or changing the padding of it doesnt work. But it is about the behaviour.

Setting a new behavior like below solves the problem but I want a proper solution.

    AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
    params.setBehavior(behavior);

First image shows the intended size, second shows the actual size.

Intended CollapsedToolbar size Results in bigger toolbar size

Here is the part of my XML: (Didn't put all of it since it is pretty long)

    <me.henrytao.smoothappbarlayout.SmoothAppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="210dp"
        android:minHeight="50dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:sabl_target_id="@id/nestedScrollView">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/transparent"
            android:fitsSystemWindows="true"
            android:minHeight="210dp"
            app:contentScrim="@color/dark_gray_actionbar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="210dp"
                android:orientation="vertical"
                app:layout_collapseMode="parallax">

                <ImageView
                    android:id="@+id/serviceImage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="Servis Fotoğrafı"
                    android:scaleType="centerCrop"
                    android:src="@drawable/gray_color_gradient"
                    app:layout_collapseMode="parallax" />
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:layout_alignParentTop="true"
                android:layout_gravity="center_horizontal"
                app:layout_collapseMode="pin">

            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </me.henrytao.smoothappbarlayout.SmoothAppBarLayout>

    <include
        layout="@layout/get_quote_layout"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        app:layout_anchor="@id/nestedScrollView"
        app:layout_anchorGravity="bottom"
        app:layout_collapseMode="pin" />


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

Upvotes: 0

Views: 1233

Answers (1)

Henry Tao
Henry Tao

Reputation: 1104

I think the issue comes from fitSystemWindows. You can simplify your layout as below:

...
<me.henrytao.smoothappbarlayout.SmoothAppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:sabl_target_id="@id/nestedScrollView">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent"
        app:contentScrim="@color/dark_gray_actionbar"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="210dp"
            android:orientation="vertical"
            app:layout_collapseMode="parallax">

            <ImageView
                android:id="@+id/serviceImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="Servis Fotoğrafı"
                android:scaleType="centerCrop"
                android:src="@drawable/gray_color_gradient"
                app:layout_collapseMode="parallax" />
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:layout_alignParentTop="true"
            android:layout_gravity="center_horizontal"
            app:layout_collapseMode="pin">

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</me.henrytao.smoothappbarlayout.SmoothAppBarLayout>
...

Upvotes: 1

Related Questions