J W*_*ebb 27 namespaces preview textview android-layout
根据这里的问题,
'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)
谢谢-
Tor*_*bye 20
我们刚刚在Android Studio 0.2.11中添加了对此类设计时属性的支持.有关更多信息,请参见http://tools.android.com/tips/layout-designtime-attributes.
将它们视为设计时助手.它们在运行时不会在实际视图渲染中得到处理.
例如,你想在android studio上设置一些视图的背景,以便你可以清楚地区分特定视图的位置.所以你通常会这样做
android:background="@color/<some-color>"
Run Code Online (Sandbox Code Playgroud)
现在的风险是,有时我们忘记删除该颜色,它会在apk中发布.相反,你可以这样做:
tools:background="@color/<some-color>"
Run Code Online (Sandbox Code Playgroud)
这些更改将是android studio的本地更改,永远不会转移到apk.
另请查看http://tools.android.com/tech-docs/tools-attributes以获取更多选项.
小智 6
tool在图形布局中设置对象时,您将找到属性.
Listview(在图形模式下) - >右键单击 - >预览列表内容 - >选择布局...
生产:
tools:listitem="@layout/customer_list_item"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15432 次 |
| 最近记录: |