【发布时间】:2016-05-23 14:45:26
【问题描述】:
我的应用使用一个带有 ViewPager 的 Activity 来交换应用页面的片段。每个其他片段都有效,但由于某种原因,其中一个片段,我的设置片段,没有。下图说明了这一点。红色区域是不需要的边距。蓝色区域是在主活动布局中定义的工具栏 - 它始终存在。绿色区域是主 ViewPager,也在主 Activity 布局中定义:
这是 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",那么每隔一个页面都会在标签栏顶部绘制通知栏,这是我不想要的。
【问题讨论】:
-
我猜是状态栏的高度。尝试玩
android:fitsSystemWindows="true" -
您是否尝试在 TextView 中删除“android:paddingTop="10dp" 并使用边距?
-
@FranklinHirata 是的,我搞砸了。
-
将
ViewPager元素的高度设置为match_parent可能会有所帮助。当前情况(包含match_parent元素的wrap_content元素)可能会导致意外结果。 -
@Thomas 尝试了你的建议,没用,但很好:(
标签: android android-layout android-studio