首页 > 解决方案 > 为什么 CoordinatorLayout 在底部显示空白?

问题描述

嗨,我的主要活动 XML 如下

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:background="@color/fcolor"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <TextView
                android:id="@+id/toolbar_title"
                style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="text"
                android:textColor="@color/scolor" />
        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_below="@+id/toolbar"
            android:background="?attr/colorPrimary"
            android:elevation="2dp"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>


<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:headerLayout="@layout/navigation_header"
    app:menu="@menu/drawer_view" />

如您所见,我使用 Include Tag 在 CoordinatorLayout 中添加了我的主要内容

  <include layout="@layout/content_main" />

在内容主要 XML 中,我有

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/actvity_main" tools:context=".Main">
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/tab_layout"/>

 </RelativeLayout>

然后我使用不同的 XML 布局在 RelativeLayout 中有 Mapview 在页面查看器中显示

我的问题是 CoordinatorLayout 左侧的屏幕底部总是有空白区域,如下图所示

在此处输入图像描述

如您所见,底部有空白,我之所以知道它来自 CoordinatorLayout,是因为当我更改 CoordinatorLayout 背景时,它会更改空间颜色

似乎我的包含标签在所有屏幕上都没有按比例缩放,即使我设置了

    <include
        layout="@layout/content_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

还是一样,我需要的是让我的 Mapview 缩放并填充屏幕底部

标签: androidandroid-layoutandroid-fragmentscoordinator-layout

解决方案


main.xml,删除android:paddingBottom="3dp"


推荐阅读