androidandroid-toolbarandroid-collapsingtoolbarlayoutandroid-appbarlayout

How to make this profile picture moving with Collapsing Toolbar Layout in Android


I want to make a layout like this. But I did not know how to make profile picture moving with CollapsingToolbarLayout. I need help.

See The Picture here

Like the above picture


Solution

  • Updated (just like the layout you want) : It is possible by adding a CircleImageView inside CoordinatorLayout so i won't be hidden after scrolling with anchoring to AppbarLayout like this:

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme">
    
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme"
                app:title="My Toolbar" />
    
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@drawable/main_bg"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />
    
    
        </android.support.design.widget.CollapsingToolbarLayout>
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:layout_collapseMode="pin">
    
            <View
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/red" />
    
            <!--Maybe a button or etc...-->
    
    
            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
    
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="My TextView"
                android:textColor="@color/whiteColor" />
    
        </FrameLayout>
    
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.widget.NestedScrollView 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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your large text" />
    
    </android.support.v4.widget.NestedScrollView>
    
    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/img_profile"
        app:layout_anchor="@id/toolbar_layout"
        app:layout_anchorGravity="bottom|center"
        app:layout_collapseMode="pin" />
    

    Output:

    enter image description here