【问题标题】:Extra margin in RelativeLayout相对布局中的额外边距
【发布时间】:2016-09-01 06:07:48
【问题描述】:

我正在使用 Support Android Percentage Library 的 RelativeLayout 又名 android.support.percent.PercentRelativeLayout它的左边缘有额外的边距,与 RelaytiveLayout 相同没有设置任何边距或填充,但它仍然有它,搜索了很多并做了任何对其他人有用的事情......但没有解决!

活动主布局代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainCoordinatorLayout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
    android:id="@+id/mainAppbarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/mainToolbar1"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary">
        <TextView
            android:id="@+id/mainTitle"
            android:text="@string/app_name"
            android:textColor="@android:color/white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </android.support.v7.widget.Toolbar>
    <android.support.v7.widget.Toolbar
        android:id="@+id/mainFlexibleSpace"
        android:layout_width="match_parent"
        android:layout_height="180dp">
       <android.support.percent.PercentRelativeLayout
           android:id="@+id/mainPercentRelativeLayout"
           android:layout_width="match_parent"
           android:layout_height="match_parent">
           <TextView
               android:id="@+id/mainEnterLink"
               android:text="@string/str_mainMessageText"
               android:gravity="center"
               android:textColor="@android:color/white"
               android:layout_width="match_parent"
               android:layout_height="wrap_content" />

       </android.support.percent.PercentRelativeLayout>
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

有什么帮助吗? See This Image of my rendered Layout Code

【问题讨论】:

  • 正如我在您的代码中看到的,您为什么要将 2 time ToolBar 添加到您的布局中?
  • 尝试添加marginleft 0并刷新
  • Ironman The Example 我使用的例子做到了这一点,我也做到了......我知道它没有必要...... :)

标签: android android-layout android-relativelayout android-percent-library margin-left


【解决方案1】:

检查工具栏是否也有问题(mainFlexibleSpace)。如果是的话,

在 java 中声明 toolBar 并执行此操作。 toolBar.setContentInsetsAbsolute(0,0);

【讨论】: