android官方技術文檔翻譯——工具屬性

來源:互聯網
上載者:User

標籤:android技術文檔   官方文檔   文檔翻譯   tools屬性   工具屬性   

本文譯自androd官方技術文檔《Tools Attributes》:http://tools.android.com/tech-docs/tools-attributes

本文地址:http://blog.csdn.net/maosidiaoxian/article/details/41510581。轉載請註明出處。翻譯如有錯訛,敬請指正。


工具屬性Android 有一個專用的XML命名空間,用於使工具可以記錄XML檔案裡的資訊,並且在打包程式的進行把資訊剝離到不會帶來運行時期和下載大小的負面影響的程度。 這個命名空間的 URI 是  http://schemas.android.com/tools,並且它通常被綁定到  tools: 首碼中:
<FrameLayout 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: ignore此屬性可以在任何 XML 元素上設定,它是一個逗號分割的lint 問題ID的列表,表示了應該要在此元素或它的任何子項目上遞迴忽略的lint問題的ID。 <string name="show_all_apps" tools:ignore="MissingTranslation">All</string>使用: Lint
tools: targetApi此屬性像 Java 類中的 @TargetApi 批註解一樣: 它允許您指定一個 API 層級,可以是整數或代碼名稱,表示此元素需要在此層級之上運行。     <GridLayout  tools:targetApi="ICE_CREAM_SANDWICH" > 使用: Lint
tools: locale此屬性可以設定在資源檔的根項目上,並且應該對應於一種語言或一個地區。這會讓工具知道檔案的字串被假定為哪種語言(地區)中的。例如,  values/strings.xml 可以有此根項目: <resources xmlns:tools="http://schemas.android.com/tools"  tools:locale="es" >
現在我們知道預設值檔案夾中的字串用的語言是西班牙語,而不是英語。使用: Lint, Studio (to disable spell checking in non-English resource files)
tools: context這個屬性通常在一個布局XML檔案的根項目中設定,記錄了這個布局關聯到哪一個activity(因為顯然一個布局在設計時可以被多個布局使用)(例如它會用於布局編輯器中以推斷預設的主題,由於主題定義在Manifest中,並與activity而不是布局相關聯。你可以和在manifests中一樣使用點首碼,來指定activity類,而不需要使用完整的程式包名作為首碼。 <android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"
     tools:context=".MainActivity"  ... >使用: Layout editors in Studio & Eclipse, Lint
tools: layout此屬性通常設定在一個 <fragment> 標籤中,用來記錄在設計時你想看到渲染的布局 (在運行時,將由這個標籤所列的fragment的類的操作所決定)。 <fragment  android:name="com.example.master.ItemListFragment"  tools:layout="@android:layout/list_content"  />使用: Studio 和 Eclipse的布局編輯器
tools: listitem /  listheader /  listfooter這些屬性可用於在設計時的 <ListView>(或其他 AdapterView 的子類,比如 <GridView>,<ExpandableListView>等) 來指定布局使用的清單項目,以及列表頭部和列表底部。該工具將填充假的資料,以顯示一個有一些類似內容的列表。     <ListView         android:id="@android:id/list"         android:layout_width="match_parent"         android:layout_height="match_parent"          tools:listitem="@android:layout/simple_list_item_2"  />使用: Studio 和 Eclipse的布局編輯器
tools: showIn該屬性設定於一個被其他布局<include>的布局的根項目上。這讓您可以指向包含此布局的其中一個布局,在設計時這個被包含的布局會帶著周圍的外部布局被渲染。這將允許您“在上下文中”查看和編輯這個布局。需要 Studio 0.5.8 或更高版本。更多資訊請參閱發布聲明。 <TextView xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:text="@string/hello_world"     android:layout_width="wrap_content"     android:layout_height="wrap_content"      tools:showIn="@layout/activity_main"  />使用:Studio 的布局編輯器
tools: menu這個屬性在布局的根項目上設定,用於配置在 Action Bar中顯示的菜單。Android Studio 通過查看這個布局檔案所連結的activity(通過 tools:context)裡的onCreateOptionsMenu()方法,嘗試找出哪些菜單在 ActionBar 中使用。它允許您重寫哪個搜尋和顯示聲明的菜單用於顯示。它的值是逗號分隔的 id 列表 (沒有 @id/ 或任何這類首碼)。您還可以使用沒有.xml 副檔名的菜單xml檔案的名稱。需要 Studio 0.8.0 或更高版本。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"      tools:menu="menu1,menu2"  />使用:Studio 的布局編輯器
tools: actionBarNavMode這個屬性在布局的根項目上設定,用於配置 Action Bar 使用的 導航模式。可能的值包括:“"standard”,“list”和“tabs”。需要 Studio 0.8.0 或更高版本。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"      tools:actionBarNavMode="tabs"  />使用:Studio 的布局編輯器
其他屬性: 設計時屬性在布局中,任何其他屬性可以是一個內建的 Android 屬性別名。例如,這可以讓您設定僅設計時的替換文字,用於工具中而不是運行時。詳細資料,請參閱設計時布局屬性。

android官方技術文檔翻譯——工具屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.