Why does TabLayout leave a gap for the NavBar when

2019-08-20 17:05发布

问题:

I'm making a tabbed app using the Tabbed Activity template in Android Studio. The client wants the tabs at the bottom and it's for use in a kiosk so I have enables immersive mode etc just fine.

My draft layout looks like this:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:layout_gravity="bottom">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

The AppBarLayout is at the bottom however there's a gap below it for the hidden nav bar:

Any suggestions?

回答1:

It turned out to be a simple fix, set fitsSystemWindows in the root view to false or remove it.

The fitsSystemWindows attribute makes your ListView fit to the edges of the action bar and navigation bar (instead of going under them).

Source