为什么 CoordinatorLayout 在底部显示白色 space?

why the CoordinatorLayout show white space in the bottom?

嗨,我有主要 activity 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 左边的屏幕底部总是空的 space,如下图

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

我的 include 标签似乎没有在所有屏幕上缩放高度,即使我设置了

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

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

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

试试这个。

试试你的 java 代码

mapView.setBuiltInZoomControls(true); 
int level = mapView.getZoomLevel();
MapController mc = mapView.getController();
mc.setZoom(level + 3);

和你的xml

<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="fill_parent"
android:layout_height="fill_parent">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true" />

        </RelativeLayout>

让我知道它是否适合你。

看起来问题是我在 java 代码中添加了填充值 感谢大家帮我检查代码中的填充

在主要内容中尝试从 RelativeLayout 中删除:

android:paddingBottom="3dp"

从 ViewPager 移动: android:layout_below="@id/tab_layout"<include layout="@layout/content_main" />

并在 ViewPager 中更改:

android:layout_height="fill_parent"android:layout_height="match_parent"