oha*_*nho 39 android android-layout
我有文章的观点.它使用"include",我试图在它们之间留一点余地.但是,"android:layout_marginTop"似乎对布局没有任何影响.
我究竟做错了什么?
<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>
Run Code Online (Sandbox Code Playgroud)
Kam*_*hev 73
您应该在标记中添加android:layout_width和android:layout_height属性include.否则,不考虑边际.
但是,如果要使用
<include>标记覆盖布局属性,则必须覆盖这两者,android:layout_height并使android:layout_width其他布局属性生效.
https://developer.android.com/training/improving-layouts/reusing-layouts.html#Include
arn*_*ans 13
我有同样的问题,Kamen Goranchev的答案对我不起作用.
我在布局编辑器中使用了ADT的功能"Extract include ..."来提取一些常用的徽章作为TextView元素的列表.所以Extract-include-tool将我的TextView-Elements包装在一个merge-tag中,这通常很好.
但是,根据从boiledwater很有帮助源代码链接我看行888 https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/LayoutInflater.java#L888的布局-只有在包含没有merge-tag作为其根元素的情况下,才会解析include-tag本身的属性.
所以我从include中删除了merge-tag,并使用了另一个ViewGroup-tag,例如FrameLayout.然后include-tag中的边距按预期工作.
include 标签支持下面的属性:
任何layout_*可以覆盖的android:属性.
android:id 属性.
layout 属性.android:visibility 属性.等等:
include android:id=”@+id/news_title”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”@layout/title”/>
请阅读:https
:
//github.com/android/platform_frameworks_base/blob/master/core/java/android/view/LayoutInflater.java#L777
http://developer.android.com/training/improving-layouts/reusing- layouts.html
另一种解决方案是在Space之前添加include:
<Space
android:layout_height="8dp"
android:layout_width="match_parent" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13188 次 |
| 最近记录: |