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

问题描述

我正在尝试制作一个折叠式工具栏,当使用滚动时,仅显示名片视图和工具栏,这意味着个人资料图片用户信息必须消失。
结果不是我想要的,
我的结果:
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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...