这是这个问题的后续问题:
Margin does not impact in "include"
我正在尝试为 include
布局添加边距。我已将 layout_width
和 layout_height
添加到 include 元素,但边距仍然被忽略。此外,当我尝试在布局 xml 文件中自动完成“边距”一词时,甚至无法识别该属性。
那么如何为 include
标签添加边距呢?
布局:
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/main_status"
/>
<!--
As the main content view, the view below consumes the entire
space available using match_parent in both dimensions.
-->
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<!--
android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead.
-->
<!--
The drawer is given a fixed width in dp and extends the full height of
the container.
-->
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left"
tools:layout="@layout/fragment_navigation_drawer" />
最佳答案
如您所见,LinearLayout 的高度设置为 match_parent
。我仍然想要那样,但这就是导致包含的布局和容器布局在尝试在我想要包含的布局内添加边距时彼此重叠的原因。
因此,为了获得我想要的效果,我所做的是设置线性布局容器的 paddingTop
属性。它在包含的布局和线性布局之间创建了一些空间。
关于android - 在包含布局上使用边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31286640/