我在标签上看过Romain Guy的帖子<merge />,但我仍然不明白它是如何有用的.它是<Frame />标签的一种替代品,还是像这样使用:
<merge xmlns:android="....">
<LinearLayout ...>
.
.
.
</LinearLayout>
</merge>
Run Code Online (Sandbox Code Playgroud)
那么<include />代码在另一个文件中?
该LayoutInflater.inflate文档是不看好的目的十分清楚我的attachToRoot参数.
attachToRoot:膨胀的层次结构是否应附加到根参数?如果为false,则root仅用于为XML中的根视图创建LayoutParams的正确子类.
有人可以更详细地解释,特别是根视图是什么,并且可能显示一个行为true和false值之间的变化的例子?
我一直在尝试了几天,现在让我的布局更有效率使用的几个层次转换嵌套LinearLayouts一个RelativeLayout和所遇到的一些问题,我的天堂没有能够找到一个解决方法...
我搜索了Android初学者小组和这个网站,但却找不到任何可以帮我解决问题的方法.
我在其中一个博客上看到,您可以将布局与合并和包含标签结合起来.所以我拥有一个带有RelativeLayout根元素的主布局文件.在其中我有5个包含标签,它们引用了5个不同的xml布局文件,每个文件都有一个根的合并元素(我的所有合并文件都是相同的,除了它们中的ID).
我遇到了两个问题,我将在发布布局代码的简化版后解释:
示例主布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/translucent_gray" >
<include
android:id="@+id/running_gallery_layout_id"
layout="@layout/running_gallery_layout" />
<include
android:id="@+id/recent_gallery_layout_id"
layout="@layout/recent_gallery_layout"
android:layout_below="@id/running_gallery_layout_id" />
<include
android:id="@+id/service_gallery_layout_id"
layout="@layout/service_gallery_layout"
android:layout_below="@id/recent_gallery_layout_id" />
<include
android:id="@+id/process_gallery_layout_id"
layout="@layout/process_gallery_layout"
android:layout_below="@id/service_gallery_layout_id" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
示例包括合并文件:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
style="@style/TitleText"
android:id="@+id/service_gallery_title_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="@string/service_title" />
<Gallery
android:id="@+id/service_gallery_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="@id/service_gallery_title_text_id" />
<TextView
style="@style/SubTitleText"
android:id="@+id/service_gallery_current_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/service_gallery_title_text_id"
android:layout_above="@id/service_gallery_id" />
</merge>
Run Code Online (Sandbox Code Playgroud)
我遇到两个问题:
1)android:layout_*在include标记中使用时,似乎忽略了属性,并且所有合并的布局都显示在彼此之上.根据这篇文章(http://developer.android.com/resources/articles/layout-tricks-reuse.html)"任何android:layout_*属性都可以与<include /> …