include 和merge 的使用对于我们最大的好处就是性能优化,大概可以优化10ms~20ms
1: include 包含,可以直接加载一个xml的layout 布局,非常方便而且节省性能,
可以加载普通的xml 也可以加载merge的xml
需要注意的是include 里面的属性,只能是layout_开头的和id
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<include layout="@layout/includedlayout"/>
<include layout="@layout/merge"/>
</LinearLayout>
2: merge 最大的好处就是和include 结合起来,相对于include 普通的xml 来说,merge 可以减少一层布局,不要少看这一层布局,这一层布局可能就是10ms的加载的时间。
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"