Android layout 隐藏Cardview&;ImageView内部折叠工具栏布局

Android layout 隐藏Cardview&;ImageView内部折叠工具栏布局,android-layout,Android Layout,每当我滚动我的活动,我希望工具栏应该保持稳定,否则一切都应该在工具栏下面。我使用了CollasingToolbarLayout和AppBarLayout,但仍然没有得到正确的解决方案 在这段代码中,CircleImageView和CardView在滚动时显示在工具栏上方 <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout

每当我滚动我的活动,我希望工具栏应该保持稳定,否则一切都应该在工具栏下面。我使用了CollasingToolbarLayout和AppBarLayout,但仍然没有得到正确的解决方案

在这段代码中,CircleImageView和CardView在滚动时显示在工具栏上方

    <?xml version="1.0" encoding="utf-8"?> 
    <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/contact_photo_height"
        android:elevation="8dp">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsideToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorAccent"
            app:title="back"
            app:titleEnabled="false"
            >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:src="@drawable/verify_image"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                android:fitsSystemWindows="true"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/tool_bar"
                app:title="back"
                app:titleTextColor="@color/white"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:contentInsetStartWithNavigation="0dp"
                android:theme="@style/ToolbarTheme"
                app:layout_collapseMode="pin"/>


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

    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_marginStart="32dp"
        android:layout_marginEnd="32dp"
        app:cardElevation="5dp"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </androidx.cardview.widget.CardView>

    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:elevation="8dp"
        android:src="@drawable/bg4"
        app:layout_anchor="@+id/cardView"
        app:layout_anchorGravity="top|center" /> 
  </androidx.coordinatorlayout.widget.CoordinatorLayout>


您缺少一个最重要的属性应用程序:卡片视图中的布局行为

  • 如果您希望所有其他内容(如cardview、circular ImageView和rest)滚动到工具栏,然后将它们合并到相对或线性布局中,并指定app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”

    
    

  • 现在,一切都将正常滚动。希望能有帮助

    您缺少一个最重要的属性应用程序:卡片视图中的布局行为

  • 如果您希望所有其他内容(如cardview、circular ImageView和rest)滚动到工具栏,然后将它们合并到相对或线性布局中,并指定app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”

    
    
  • 现在,一切都将正常滚动。希望能有帮助

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_marginStart="32dp"
        android:layout_marginEnd="32dp"
        app:cardElevation="5dp"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
    
    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:elevation="8dp"
        android:src="@drawable/bg4"
        app:layout_anchor="@+id/cardView"
        app:layout_anchorGravity="top|center" />
     </LinearLayout>