Android - Frame layout height not matching with coordinator layout

前端 未结 2 970
野性不改
野性不改 2021-02-14 07:12

I have a problem with my FrameLayout (Container in Drawer Layout). The height of the FrameLayout exceeds the screen height (below the android default menu buttons at bottom).

2条回答
  •  再見小時候
    2021-02-14 07:55

    My first attempt was to set a android:layout_marginBottom="?attr/actionBarSize" at the FrameLayout. This solved the solution for non-scrollable views having a "fixed" height in terms of no vertically scrollable content (like a usual RelativeLayout with match_parent height). Aligning a component to the parent bottom (android:layout_alignParentBottom="true") results in a still visible element. In Android Studio's Previewer the no exceeding of the height is visible.

    However, this marginBotton-fix introduces a new problem for fragments whose root view is scrollable (like a RecyclerView). For these views when scrolling down the bottom margin will become visible in a white bar (in case white is the background color). This seams reasonable, as for those views the nested scrolling feature will slide out the toolbar

    tl;dr I worked around that issue by applying the the ?attr/actionBarSize as bottom margin to non-scrollable fragments that are shown inside the Framelayout. Prior to that I set the height of the toolbar to be ?attr/actionBarSize.

    Activity layout:

            
    
                
    
            
    
            
    
    
    

    Fragment layout:

    
              
              
      
    

    The only downside I faced right now is the white space to be shown in Android Studio's Previewer while creating the fragment layout.

提交回复
热议问题