微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用约束布局处理折叠工具栏

如何解决如何使用约束布局处理折叠工具栏

我正在尝试制作一个折叠式工具栏,当使用滚动时,仅显示名片视图和工具栏,这意味着个人资料图片用户信息必须消失。
结果不是我想要的,
我的结果:
when I run the app

when I scroll and move down


我的xml(我删除了大部分内容,因为它很长。但是我保留了主要的构造函数和主要的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/appBarLayout"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
            app:contentScrim="@color/colorPrimary"
            app:title="@string/app_name">
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:background="@null"
                >
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="left"
                    android:src="@drawable/arrow"
                    android:layout_marginLeft="17dp"
                    ></ImageView>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="My profile"
                    android:textSize="15sp"
                    android:layout_gravity="center"
                    android:id="@+id/toolbar_title1"
                    android:fontFamily="sans-serif-black"
                    android:textColor="#737373
"

                    />


                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:src="@drawable/chat1"
                    android:layout_gravity="right"
                    android:layout_marginRight="17dp"


                    />



            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.nestedScrollView

        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/profile_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="#f0f0f4"

        android:elevation="4dp"
        android:paddingBottom="24dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar1"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:background="@null"
            >
            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="left"
                android:src="@drawable/arrow"
                android:layout_marginLeft="17dp"
                ></ImageView>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="My profile"
                android:textSize="15sp"
                android:layout_gravity="center"
                android:id="@+id/toolbar_title"
                android:fontFamily="sans-serif-black"
                android:textColor="#737373
"

                />


            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/chat1"
                android:layout_gravity="right"
                android:layout_marginRight="17dp"


                />



        </androidx.appcompat.widget.Toolbar>


        <RelativeLayout
            android:id="@+id/profile_picture1"
            android:layout_width="match_parent"
            android:layout_height="230dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/toolbar1">

          
//here there is frame layout for profile picture

        </RelativeLayout>

        
    
      //here there is linear layouts for user information




        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/buttons"
            >


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linear1"
                >


// the card views here

            </RelativeLayout>

        </RelativeLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.core.widget.nestedScrollView>
    
</androidx.coordinatorlayout.widget.CoordinatorLayout>

如何解决??

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。