Android 整个布局上方的奇怪边距

Android 整个布局上方的奇怪边距,android,android-layout,android-studio,Android,Android Layout,Android Studio,我的应用程序使用一个带有ViewPager的活动来交换应用程序页面的片段。其他每个片段都有效,但出于某种原因,其中一个片段“我的设置片段”无效。下图说明了这一点。红色区域是不需要的边距。蓝色区域是在主活动布局中定义的工具栏-它始终在那里。绿色区域是主ViewPager,也在主活动布局中定义: 这是MainActivity布局的外观: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml

我的应用程序使用一个带有ViewPager的活动来交换应用程序页面的片段。其他每个片段都有效,但出于某种原因,其中一个片段“我的设置片段”无效。下图说明了这一点。红色区域是不需要的边距。蓝色区域是在主活动布局中定义的工具栏-它始终在那里。绿色区域是主ViewPager,也在主活动布局中定义:

这是MainActivity布局的外观:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity"
android:fitsSystemWindows="true" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Tab Bar -->
    <com.rentalapp.rentmi.views.SlidingTabLayout
        android:id="@+id/main_content_pager_tab_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="@color/primary" />

    <!-- Content Pager -->
    <android.support.v4.view.ViewPager
        android:id="@+id/main_content_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main_content_pager_tab_bar" />

</RelativeLayout>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Settings"
        android:id="@+id/textView2"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:paddingTop="10dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Log Out"
        android:id="@+id/logout"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:paddingTop="10dp" />

</RelativeLayout>

这就是设置片段的样子:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity"
android:fitsSystemWindows="true" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Tab Bar -->
    <com.rentalapp.rentmi.views.SlidingTabLayout
        android:id="@+id/main_content_pager_tab_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="@color/primary" />

    <!-- Content Pager -->
    <android.support.v4.view.ViewPager
        android:id="@+id/main_content_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main_content_pager_tab_bar" />

</RelativeLayout>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Settings"
        android:id="@+id/textView2"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:paddingTop="10dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Log Out"
        android:id="@+id/logout"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:paddingTop="10dp" />

</RelativeLayout>


如何修复这个不需要的边距?如果我从主布局中删除
android:fitsystemwindows=“true”
,那么每隔一页就会在选项卡栏顶部绘制通知栏,这是我不想要的。

不知道如何删除,但我可以通过删除我拥有的
android:fitsystemwindows=“true”
来修复它。过去把它去掉会破坏一切。现在它修好了

我猜是状态栏的高度。试着玩一下
android:fitsystemwindows=“true”
你有没有试着删除TextView中的“android:paddingTop=“10dp”并使用margin?@FranklinHirata是的,我已经弄糟了。这可能有助于将
ViewPager
元素的高度设置为
匹配父元素(一个
wrap\u content
元素包含一个
match\u parent
元素)可能会导致意外的结果。@Thomas尝试了你的建议,但没有成功,但很好地抓住了:(