android xml布局文件中tools:layout的作用
用最新版本的adt 創建一個基于master/detail flow 模版的app的時候,生成的activity_item_list.xml
文件中有一個tools:layout屬性:
fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/item_list" android:name="com.example.fragmenttwopanel.ItemListFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" tools:context=".ItemListActivity" tools:layout="@android:layout/list_content" />
一開始不明白,后來刪掉這個屬性之后發現會出現一個提示:
pick preview layout from the "Fragment Layout" context menu
原來tools:layout僅僅是告訴編輯器,Fragment在程序預覽的時候該顯示成什么樣,并不會對apk產生實際作用,是為開發者設計的。
一般來說被xmlns:tools="http://schemas.android.com/tools"
聲明的tools作為前綴的屬性都不會被編譯進去。這個跟上面代碼中tools:context
是一樣的。
本文由用戶 bisdd62qa 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!