android - 为什么 CoordinatorLayout 在底部显示空白?

标签 android android-layout android-fragments coordinator-layout

您好,我的主要 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 布局,让 Mapview 在relativelayout中显示在页面查看器中

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

enter image description here

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

即使我设置了,我的包含标签似乎也无法在所有屏幕上缩放

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

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

最佳答案

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

关于android - 为什么 CoordinatorLayout 在底部显示空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50721693/

相关文章:

android - 在回收站 ListView 项目之间添加了大空间

android - 在服务中断时暂停/停止/静音音乐

java - 坚持 View 滚动以跟随 Sprite

android - 实现 Fragment 实例化会产生相反的效果

android - ConstraintLayout 中的 RecyclerView 与其他元素重叠

java - 如何用gif动画替换进度对话框的消息?

android - 使用带有文本和图像的自定义适配器在 ListView 中搜索

android - ImageView 膨胀但不显示图像

android - 是否可以在一个布局中制作两个具有相同 ID 的按钮?

java - 使用应用程序 :srcCompat 自定义 ImageView 背景绘制