从最新的ADT版本开始,我注意到布局XML文件上的这个新属性,例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" />
Run Code Online (Sandbox Code Playgroud)
什么是"工具:上下文"用于?
它怎么知道写在那里的活动的确切路径?它是否在清单中查看应用程序的包?
它仅限于扩展Context或仅扩展活动的类吗?它可用于ListView项目等吗?
xml android android-context android-layout android-tools-namespace
根据这里的问题,
'tools'命名空间引用(xmlns:tools ="http://schemas.android.com/tools")最近已经开始出现在我的布局中,我想知道更多.原帖只描述了'tools:context'属性,但我也注意到当我为listview指定预览布局项时出现的"tools:listitem"属性的使用,即
<ListView
android:id="@+id/lvCustomer"
tools:listitem="@layout/customer_list_item" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
还有更多元素吗?
是什么让我进入这个'工具'命名空间是因为我希望在eclipse中使用布局设计器时能够拥有'仅预览'文本(即在TextView或EditText中).
目前,我在安排布局时指定'text'或'hint'属性来预览文本...但是我总是要记住从代码中清除预览值.
理想情况下,而不是
<string name="preview_customer_name">Billy Bob's Roadhouse Pub</string>
...
<TextView
android:id="@+id/tvCustomerName"
android:text="@string/preview_customer_name"
</TextView>
Run Code Online (Sandbox Code Playgroud)
有类似的东西:
<TextView
android:id="@+id/tvCustomerName"
tools:previewText="@string/preview_customer_name"
</TextView>
Run Code Online (Sandbox Code Playgroud)
谢谢-
我使用ADT Eclipse基于主/详细流模板启动了一个新的Android应用程序.此模板创建两个活动,主片段和细节片段,以适应较小和较大的屏幕.
我注意到该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" />
Run Code Online (Sandbox Code Playgroud)
我试图删除属性,应用程序以相同的方式运行,但在ADT的图形布局选项卡中,一条消息要求我:
从"片段布局"上下文菜单中选择预览布局
它的目的是什么?它只是用于图形布局的预览吗?