I am building an application and there is a profile fragment which shows a profile background image and some other elements. Like the screenshot below:
My quest
I recently faced a similar issue, this was due to the insets,as the collapsing toolbar is drawn behind the statusbar , it provides the additional height of the status bar, in order to avoid this issue, I found a better solution , instead of a calculating a height of collapse toolbar, let the toolbar consume the insets
ViewCompat.setOnApplyWindowInsetsListener(appBarLayout) { v, insets ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
toolBar.setPadding(0, insets.systemWindowInsetTop, 0, 0)
}
insets.consumeSystemWindowInsets()
}
This thing worked , instead of calculating the height I would recommend to go through the following links
Ian Lakes article
Chris Banes talk
Give it a try