【问题标题】:Strange margin above entire layout整个布局上方的奇怪边距
【发布时间】: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


【解决方案1】:

不知道怎么做,但我可以通过删除我拥有的android:fitsSystemWindows="true" 来修复它。在过去删除它会破坏一切。现在它修复了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 2011-10-11
    • 2011-04-29
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多