[英]Debugging Android Collapsing Toolbar - insets and onResume
我注意到我實現的折疊工具欄有兩個小問題。 我注意到的第一件事是它在工具欄和它下面的回收器視圖/嵌套滾動視圖之間應用了一個插圖,創建了一個明顯的間隙,如圖 A 所示
我注意到的第二個問題是當我向下滾動列表並且工具欄折疊時。 如果我單擊一個回收器視圖項並導航到下一個片段,然后單擊后退按鈕並返回導航,工具欄將折疊,但是圖像是可見的,需要一兩秒鍾才能制作動畫並再次變為不可見如圖 B 所示。
我的 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.