如何使用Android中的折叠工具栏布局使此个人资料图片移动

问题描述 投票:1回答:1

我想制作这样的布局。但我不知道如何使用CollapsingToolbarLayout制作个人资料图片。我需要帮助。

如上图所示

android android-toolbar android-collapsingtoolbarlayout android-appbarlayout
1个回答
0
投票

更新(就像你想要的布局):可以通过在CircleImageView中添加一个CoordinatorLayout,所以在滚动锚定到AppbarLayout之后我不会被隐藏,如下所示:

<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" />

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.