Android 保证金不影响;包括「;
我对文章有看法。它使用“include”,我试图在它们之间留一点余地。然而,“android:layout_marginTop”似乎对布局没有任何影响 我做错了什么Android 保证金不影响;包括「;,android,android-layout,Android,Android Layout,我对文章有看法。它使用“include”,我试图在它们之间留一点余地。然而,“android:layout_marginTop”似乎对布局没有任何影响 我做错了什么 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <include android:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include android:id="@+id/article1" layout="@layout/mainarticle" />
<include android:id="@+id/article2" android:layout_marginTop="10dip" layout="@layout/article" />
<include android:id="@+id/article3" android:layout_marginTop="10dip" layout="@layout/article" />
<include android:id="@+id/article4" android:layout_marginTop="10dip" layout="@layout/article" />
<include android:id="@+id/article5" android:layout_marginTop="10dip" layout="@layout/article" />
</LinearLayout>
您应该在
include
标签中添加android:layout\u width
和android:layout\u height
属性。否则,不考虑利润
但是,如果要使用
标记覆盖布局属性,则必须同时覆盖android:layout\u height
和android:layout\u width
,才能使其他布局属性生效
包括属性下面的标签支持:
任何android:layout.*
可以覆盖的属性
android:id
属性
布局
属性
android:visibility
属性
等等:
包括android:id=“@+id/news\u title”
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
layout=“@layout/title”/>
请阅读:
我也有同样的问题,卡门·戈兰切夫的答案对我来说并不适用
我从布局编辑器中使用了ADT的功能“Extract include…”,将一些常用的徽章提取为TextView元素列表。因此,Extract包含工具将my TextView元素包装在一个合并标记中,这通常很好
但是,根据我在第888行看到的来自boiledwater的非常有用的源代码链接,只有当include没有将merge标记作为其根元素时,才会解析include标记本身的布局属性
因此,我从包含中删除了合并标记,并使用了另一个视图组标记,如FrameLayout。然后include标记中的边距按预期工作。另一个解决方案是在include
之前添加空格:
<Space
android:layout_height="8dp"
android:layout_width="match_parent" />
必须在其他布局中插入include
e、 g.相对性
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/sub_edit_new_customer" />
</RelativeLayout>
在我的例子中,我通过添加一些填充来解决问题
要包括的布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"> <!-- add padding here -->
<!-- your custom layout -->
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
奇怪,但却是真的。。thnxThis仅在include xml本身没有作为根元素的合并标记时有效,请参阅下面的我的答案。感谢您提供的链接,这对我下面的答案非常有帮助!对你的答案投了赞成票!美好的感谢您添加此特殊情况。