2016-05-23 66 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