繁体   English   中英

调试 Android 折叠工具栏 - insets 和 onResume

[英]Debugging Android Collapsing Toolbar - insets and onResume

我注意到我实现的折叠工具栏有两个小问题。 我注意到的第一件事是它在工具栏和它下面的回收器视图/嵌套滚动视图之间应用了一个插图,创建了一个明显的间隙,如图 A 所示

图片 A 插图间隙

我注意到的第二个问题是当我向下滚动列表并且工具栏折叠时。 如果我单击一个回收器视图项并导航到下一个片段,然后单击后退按钮并返回导航,工具栏将折叠,但是图像是可见的,需要一两秒钟才能制作动画并再次变为不可见如图 B 所示。

工具栏图像可见 1 秒 onResume 从其他片段

我的 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:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/logs_header"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@color/logs_header">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/child"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax">

            <ImageView
                android:id="@+id/headerImage"
                android:layout_width="match_parent"
                android:layout_height="@dimen/checkin_header_image"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_logs_header" />

            <ImageView
                android:id="@+id/brain"
                android:layout_width="@dimen/layout_brain_size"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_32sdp"
                android:adjustViewBounds="true"
                app:layout_collapseMode="parallax"
                 app:layout_constraintBottom_toBottomOf="@+id/headerImage"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/headerImage"
                app:srcCompat="@drawable/brain_workout_logs" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/heading"
                style="@style/heading.style"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/heading_margin_lr"
                android:layout_marginTop="@dimen/heading_margin_top"
                android:layout_marginEnd="@dimen/heading_margin_lr"
                android:text="@string/logs_title"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/headerImage" />

            <View
                android:id="@+id/dividerHeading"
                android:layout_width="match_parent"
                android:layout_height="@dimen/divider_height"
                android:layout_marginStart="@dimen/divider_heading_lr"
                android:layout_marginTop="@dimen/_12sdp"
                android:layout_marginEnd="@dimen/divider_heading_lr"
                android:background="?android:attr/dividerVertical"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/heading" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbarContainer"
            android:layout_width="match_parent"
            android:layout_height="@dimen/toolbar_height"
            android:background="@color/transparent"
            app:contentInsetStart="0dp"
            app:layout_collapseMode="pin">

            <include
                android:id="@+id/toolbarLayout"
                layout="@layout/toolbar_logs" />
        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
    android:id="@+id/childContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvLogs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_6sdp"
            android:layout_marginEnd="@dimen/_6sdp"
            android:nestedScrollingEnabled="false"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

任何人都可以帮我解决这两个小错误的根本原因吗?

对于空间问题,您必须从根 CoordinatorLayout 中删除android:fitsSystemWindows="true"属性。 如果它是真的,那么它会调整这个视图的填充为系统 windows (例如:状态栏)留出空间。 根据文档

Boolean 内部属性,用于根据状态栏等系统 windows 调整视图布局。 如果为 true,则调整此视图的填充以为系统 windows 留出空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM