[CollapsingToolbarLayout] Wrong height for wrap_content while children have fitSystemWindows set to true
See original GitHub issueDescription: At onMeasure()
in CollapsingToolbarLayout
, it adds topInset
to the measured height, which can be unnecessary and cause a gap to appear at the bottom if children have fitSystemWindow
set to true
.
ImageView
with fitSystemWindow = false
ImageView
with fitSystemWindow = true
Expected behavior:
View height should be measured considering fitSystemWindow
of children.
Source code:
<?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"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:fitsSystemWindows="true"
android:src="@drawable/hero"/>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_scrolling">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/large_text"/>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Android API version: 28
Material Library version: 1.1.0-alpha09
Device: Pixel 2 XL / Pixel 2 Emulator
Issue Analytics
- State:
- Created 4 years ago
- Reactions:14
- Comments:5 (1 by maintainers)
Top Results From Across the Web
AppBarLayout fitSystemtWindows=“true" does not work when ...
I want to build a collapsing Toolbar with views add to CollapsingToolBarLayout dynamically. so i need to set AppBarLayout wrap_content . Then i ......
Read more >Android CollapsingToolbarLayout Example - DigitalOcean
Android CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child...
Read more >Handling Scrolls with CoordinatorLayout - CodePath Cliffnotes
When this setting is used, your view will only appear at this minimum height. Only when scrolling reaches to the top will the...
Read more >Design Support Library (IV): Collapsing Toolbar Layout
Collapsing Toolbar Layout will help us create amazing transition animations when scrolling an activity content and using an image parallax.
Read more >Set Starting Height Of Collapsingtoolbarlayout - ADocLib
[CollapsingToolbarLayout] Wrong height for wrapcontent while children have fitSystemWindows set to true #520. Open. hiking93 opened this.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve solved the issue as follow.
i have solve it.
remove “android:fitsSystemWindows=true” from CollapsingToolbarLayout.