在include某個布局的時候蒙保,被include的布局頂部使用merge布局可以有效減少布局嵌套,如果是替換LinearLayout等其他布局更是有效提高性能
tools:parentTag="LinearLayout" 和 tools:orientation="horizontal" 都是讓android studio預(yù)覽的時候可以以LinearLayout形式觀看
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:parentTag="LinearLayout"
tools:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some other text"/>
</merge>