Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

collapse CollapsingToolbarLayout COMPLETELY

I use CollapsingToolbarLayout in an AppBarLayout only for its parallax effect while scrolling, so I need to collapse the layout completely. I mean set its height to zero after scrolling down. I set the layout minHeight to 0dp but doesn't work, and still have some part of layout visible.

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="40dp"
        android:paddingRight="40dp"
        android:paddingLeft="40dp"
        android:background="#e91e63"
        android:fitsSystemWindows="true"
        android:minHeight="0dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="0dp"
            android:fitsSystemWindows="true"
            app:titleEnabled="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                    android:id="@+id/index_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/suitcase"
                    android:padding="20dp"
                    android:background="@drawable/index_page_icon_bg"
                    android:layout_margin="5dp"
                    app:layout_collapseMode="parallax"/> 

            </LinearLayout>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:minHeight="0dp"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>   
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
        </android.support.v4.widget.NestedScrollView>

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

what happens which I don't want

General Rule: If you think this is not a good Q, declare at comments then do whatever you like!

like image 410
Mneckoee Avatar asked Apr 10 '16 06:04

Mneckoee


1 Answers

Change the AppBarLayout like this .

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#e91e63"
    android:fitsSystemWindows="true"
    android:minHeight="0dp"
    android:theme="@style/AppTheme.AppBarOverlay">

an the ImageView will be like this .

  <LinearLayout
    android:paddingTop="40dp"
    android:paddingRight="40dp"
    android:paddingLeft="40dp"
    android:scaleType="fitXY"
    app:layout_collapseMode="parallax"
    app:layout_collapseParallaxMultiplier="0.4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/index_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/suitcase"
        android:padding="20dp"
        android:background="@drawable/index_page_icon_bg"
        android:layout_margin="5dp" />

</LinearLayout>

The problem was, you make a padding top in the AppBarLayout , so when it collapse it still make the 40dp padding , so the layout can't make Full collapse.

like image 193
Zahidul Islam Avatar answered Sep 28 '22 02:09

Zahidul Islam