Home Design

by Androidhunt

Moving where we handle insets to where our views live, layout files

Chris Banes
android:layout_height="wrap_content"
android:layout_width="match_parent" />
Image for post

Image for post

rootView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION


#80FFFFFF

true
Image for post

Image for post

The view is being displayed behind the navigation bar
bottomNav.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(bottom = insets.systemWindowInsetBottom)
insets
}
Image for post

Image for post

The view now has bottom padding which matches the navigation bar size
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingVertical="24dp" />
Image for post

Image for post

The view has the correct top padding, but the intended bottom padding isn’t there
bottomNav.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(
bottom = view.paddingBottom + insets.systemWindowInsetsBottom
)
insets
}
Image for post

Image for post

The accumulated padding after 3 WindowInset dispatches
// Keep a record of the intended bottom padding of the view
val bottomNavBottomPadding = bottomNav.paddingBottom

bottomNav.setOnApplyWindowInsetsListener { view, insets ->
// We've got some insets, set the bottom padding to be the
// original value + the inset value
view.updatePadding(
bottom = bottomNavBottomPadding + insets.systemWindowInsetBottom
)
insets
}

Image for post

Image for post

Finally, what we intended
bottomNav.doOnApplyWindowInsets { view, insets, padding ->
// padding contains the original padding values after inflation
view.updatePadding(
bottom = padding.bottom + insets.systemWindowInsetBottom
)
}
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingVertical="24dp"
app:paddingBottomSystemWindowInsets="@{ true }" />
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingVertical="24dp"
app:paddingBottomSystemWindowInsets="@{ true }"
app:paddingLeftSystemWindowInsets="@{ true }"
/>

android:fitSystemWindows

You may also like

Leave a Reply