2016-05-23 71 views
3

我的应用使用一个ViewPager活动来交换应用页面的片段。其他每个片段都可以工作,但由于某种原因,其中一个片段(我的设置片段)没有。下图说明了这一点。红色区域是不必要的边缘。蓝色区域是主活动布局中定义的工具栏 - 始终存在。绿色区域是主要ViewPager,在主活动布局还定义:高于整个布局的奇怪边距

enter image description here

这是在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> 

我该如何解决这个不需要的保证金?如果我从主布局中删除android:fitsSystemWindows="true",则每个其他页面都会在标签栏顶部绘制通知栏,这是我不想要的。

+0

我想这是状态栏的高度。尝试玩 'android:fitsSystemWindows =“true”' – convexHull

+0

您是否试图删除TextView中的“android:paddingTop =”10dp“并使用margin? –

+0

@FranklinHirata是的,我搞砸了这些。 – Dooskington

回答

8

不知道如何,但我能通过删除我有的一个android:fitsSystemWindows="true"来解决它。去除过去打破了一切。现在它修复了它。

+0

谢谢你,确实很奇怪,但它的工作原理:D – mohnage7