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

标签 android android-toolbar android-collapsingtoolbarlayout android-appbarlayout

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

See The Picture here

如上图所示

最佳答案

更新(就像您想要的布局):可以通过在 CoordinatorLayout 内添加 CircleImageView 来实现所以在锚定到 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

关于android - 如何使用 Android 中的折叠工具栏布局使此个人资料图片移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52069383/

相关文章:

java - 未找到启动器 Activity

android - Gradle 必须依赖 com.google.firebase :firebase-core for Firebase services to work as intended

android - 如何在 Android Dialog 中居中布局?

android - 后退箭头 工具栏正在打开抽屉

android - 以编程方式折叠或展开 CollapsingToolbarLayout

Android:尝试获取 AppBarLayout LayoutParams 时应用程序崩溃

android - Android WebView调整默认音频播放器的大小

android - 后退按钮在 actionBar 中不起作用

android - AppBarLayout 上方显示的 FrameLayout

android - 我可以在抽屉导航的 fragment 中使用 CollapsingToolbarLayout