android - 在包含布局上使用边距

标签 android android-layout include

这是这个问题的后续问题:

Margin does not impact in "include"

我正在尝试为 include 布局添加边距。我已将 layout_widthlayout_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/

相关文章:

delphi - 如何查看哪个单元使用另一个单元的层次结构? (德尔福)

android - Android Fragment 中的 EditText 值不刷新

android - OnPause 和返回按钮

parsing - 如何使用 Flex 和 YACC 实现 #include 结构?

android - 如何像 Android 的联系人应用程序一样构建快速操作栏?

android - Android 中 DecorView 和 ViewRootImpl 之间的关系是什么?

javascript - 我如何在 javascript 中包含 mvc3 razor 变量?

java - 单击监听器上的单选按钮仅在选择切换按钮后才起作用

Android 在 AlertDialog 中验证 EditText

android - 如何以编程方式(在运行时)滑动一行 RecyclerView?