提升布局性能____Re-using Layouts with <include/>
2016-12-10 15:28
417 查看
可以再一个布局中通过“include”和“merge”元素进行复用其他的布局元素。
比如如下一个布局:
这是一个可复用的布局文件,倘若有以下的布局文件:
则包含了被复用的文件。
当然,如果在包含者当中,需要调整被包含者的属性,也可以:
这样就重新调整了被包含者的属性。
android中海油另一个“merge”标签,看了官方文档后,我个人理解是这样:
假使主布局中的根元素是线性布局,通过include包含了一个子布局,该子布局的根元素仍然是线性布局,那么包含后就与主布局的线性元素重复了,所以可以通过“merge”来解决,
比如如下一个布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width=”match_parent” android:layout_height="wrap_content" android:background="@color/titlebar_bg"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/gafricalogo" /> </FrameLayout>
这是一个可复用的布局文件,倘若有以下的布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width=”match_parent” android:layout_height=”match_parent” android:background="@color/app_bg" android:gravity="center_horizontal"> <include layout="@layout/titlebar"/> <TextView android:layout_width=”match_parent” android:layout_height="wrap_content" android:text="@string/hello" android:padding="10dp" /> ... </LinearLayout>
则包含了被复用的文件。
当然,如果在包含者当中,需要调整被包含者的属性,也可以:
<include android:id=”@+id/news_title” android:layout_width=”match_parent” android:layout_height=”match_parent” layout=”@layout/title”/>
这样就重新调整了被包含者的属性。
android中海油另一个“merge”标签,看了官方文档后,我个人理解是这样:
假使主布局中的根元素是线性布局,通过include包含了一个子布局,该子布局的根元素仍然是线性布局,那么包含后就与主布局的线性元素重复了,所以可以通过“merge”来解决,
<merge xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/add"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/delete"/> </merge>
相关文章推荐
- 提升布局性能____Re-using Layouts with <include/>
- 提升布局性能____Re-using Layouts with <include/>
- Android最佳实践性能(三)提高性能布局(再利用布局与<include/>')
- Android最佳性能实践——布局优化技巧之<include>、<merge>标签及仅在需要时才加载布局的:ViewStub
- android_应用开发之(使用<include>标签重用布局)
- 【移动开发】布局优化利器<include/>和ViewStub
- Re-using Layouts with include
- [Android 性能优化系列]布局篇之通过<include>复用布局
- [Android 性能优化系列]布局篇之通过<include>复用布局
- C++ #include<string> 和 using std::string
- 【移动开发】布局优化利器<include/>和ViewStub
- 详解C++中经常看到的#include <iostream> using namespace std;
- android 布局优化标签<include/>、<merge />、<ViewStub />
- Android Developers:使用<include/>重用布局
- 布局文件的引入<include>标签的使用
- 布局优化技巧--<include>/<merge>/<viewStub>
- Android中View绘制优化二一---- 使用<include />标签复用布局文件
- #include &lt;iostream.h&gt; 和 #include &lt;iostream&gt; using namespace std的区
- android 布局性能优化(<include />)
- #include <iostream> using namespace std; C++命名空间是什么?