ViewGroup inside CollapsingToolbarLayout show extra bottom padding when set fitsSystemWindows to be true

前端 未结 7 2518
有刺的猬
有刺的猬 2021-02-08 15:05

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

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-08 15:59

    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

提交回复
热议问题