Joe Rakhimov
Joe Rakhimov

Reputation: 5083

How to make Collapsing Toolbar not collapsed fully?

I have collapsing toolbar which is collapsing correctly:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="453dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|snap|snapMargins"
            app:toolbarId="@+id/toolbar">

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#FFFF00" />

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

    <include layout="@layout/content_scrolling" />

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

I am trying to make collapsing toolbar collapsed not fully. Here is the example:

enter image description here

My question: how to make collapsing toolbar collapsed not fully?

Upvotes: 2

Views: 1415

Answers (1)

sumit sonawane
sumit sonawane

Reputation: 1555

set inner view property app:layout_collapseMode="pin"

<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:background="@color/white"
android:orientation="vertical">


<android.support.design.widget.AppBarLayout
    android:id="@+id/mAppBarContainer"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_350sdp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
        app:scrimAnimationDuration="100"
        app:titleEnabled="false">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="pin">

            <ImageView
                android:id="@+id/mPreview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:adjustViewBounds="true"
                android:contentDescription="@string/app_name"
                android:elevation="8dp"
                app:layout_scrollFlags="scroll|enterAlways" />


            <TextView
                android:id="@+id/txt_placeholder"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="No Image Found"
                android:textColor="@color/white"
                android:textSize="@dimen/_20sdp"
                android:visibility="gone" />
        </RelativeLayout>

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

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

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

Upvotes: 1

Related Questions