android Merge标签
生活随笔
收集整理的這篇文章主要介紹了
android Merge标签
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.Merge標簽
主要是進行UI布局優(yōu)化。<merge/>主要是: 1.用來替換FrameLayout或者當一個布局(根節(jié)點布局)嵌套布局的時。 2.<merge/>標簽用于消除師徒層次結構中多余的視圖組。 復制代碼2.實例來表示
(1)沒有使用Merge標簽代碼: 復制代碼 <?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns: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"tools:context="demo.zhiyunqiao.com.merge.MainActivity"tools:layout_editor_absoluteY="81dp"><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"/></RelativeLayout> 復制代碼用DDMS檢測出來的布局層級: 復制代碼 可以看到上面的層級布局中,跟布局還有個FrameLayout布局。 (2)使用了Merge標簽代碼: <?xml version="1.0" encoding="utf-8"?> <mergexmlns: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"tools:context="demo.zhiyunqiao.com.merge.MainActivity"tools:layout_editor_absoluteY="81dp"><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"/> </merge> 復制代碼DDMS檢測結果:
可以看到我們少了一層布局RelativeLayout布局這樣我們就少了一層布局。3.需要注意:
1.某些時候,自己定義可重用的布局包括了過多的層級標簽,比方我們比如:這種話。使用<include>包括上面的布局的時候。系統會自己主動忽略merge層級 實例表示: (1)include代碼: 復制代碼 添加include到main_activity中的效果: 可以看出上面的差異,在include中有Merge標簽的時候會被忽略。4.merge的使用限制
merge只能作為XML布局的根標簽使用。當Inflate以merge開頭的布局文件時,必須指定一個父ViewGroup,并且必須設定attachToRoot為true。 復制代碼 《新程序員》:云原生和全面數字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的android Merge标签的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷1020导弹拦截
- 下一篇: 吴恩达:现在很多所谓的AI公司,其实都不