Android有一个专门的工具类XML命名空间,用于在XML文件中记录信息,而且这些信息会在程序打包时被去掉,所以不会造成运行时和下载的负担。这个命名空间的URI是http://schemas.android.com/tools,常用前缀是tools:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    <strong>xmlns:tools="http://schemas.android.com/tools"</strong>    android:layout_width="match_parent"    android:layout_height="match_parent" >    ....
这篇文档记录了我们常用的工具类属性(这可能会经常变 化)。

tools:ignore

这个属性可以应用在任何XML元素上,它的值是用逗号分隔的Lint问题ID,表示该元素及其子元素都忽略这些问题。

<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>

用于:Lint.

tools:targetApi

这个属性就像Java中的@TargetApi注解。它让你指定该元素运行时的API级别,可以是API的数值,也可以示API的名字。

<GridLayout tools:targetApi="ICE_CREAM_SANDWICH" >

用于:Lint.

tools:locale

该属性可以用在资源Value文件的跟元素上,它对应一种语言(可以加上一个区域)。这样工具类就知道文件中的字符串究竟是哪个语言(或者区域的)。举个例子,values/strings.xml 可以这样指定跟元素

<resources xmlns:tools="http://schemas.android.com/tools" <strong>tools:locale="es"</strong>>

这样我们就知道缺省Values文件夹中的使用的语音是西班牙语而不是英语。

用于:Lint,Studio(关闭资源文件中的拼写检查).


其他的就没翻译了:

tools:context

用于layout猜测布局预览时使用的主题。因为主题一般在Manifest文件中指定,而且主题之和Activity关联,而不是layout。
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"    <strong>tools:context=".MainActivity"</strong> ... 

tools:layout

用在<fragment>标签上,用于指定设计时设计器渲染的layout。

<fragment android:name="com.example.master.ItemListFragment" <strong>tools:layout="@android:layout/list_content"</strong> />

其他的,就不多说了

tools:listitem /listheader /listfooter

tools:showIn

tools:menu

tools:actionBarNavMode



Designtime Layout Attributes

可以用tools:xxxxx属性指定设计时的android:xxxxx属性。


首先得在布局文件中加上命名空间:

<LinearLayout        xmlns:android="http://schemas.android.com/apk/res/android"       <strong> xmlns:tools="http://schemas.android.com/tools"</strong>        android:layout_width="match_parent"        ...


举个例子:想在设计时,让TextView显示“aaa”,而在正式运行时不显示该字符串。只要这样:

<TextView      <strong>       tools:text="aaa"</strong>            android:layout_width="wrap_content"            android:layout_height="wrap_content" />







更多相关文章

  1. android 控件: xml 设置 Button 按下背景
  2. Android(安卓)Studio 生成的目录,对应应用Logo的尺寸___ AS 与 Ec
  3. Android使用Gradle进行打包混淆,包括依赖Library
  4. 如何将当前布局用代码保存在png图像文件中?
  5. android学习笔记(一) 遍历SD卡中所有文件并在listview中显示
  6. Android(安卓)studio打包生成apk
  7. Android(安卓)Studio中无法找到android.os.SystemProperties解决
  8. 解决S5pv210 adb push u-boot.bin /system 的失败问题
  9. 【转】备份:Android(安卓)常用 mimeType 表

随机推荐

  1. Android Camera数据流分析全程记录
  2. 【转载】微信Android 视频编码爬过的那些
  3. android 内存和性能优化汇总
  4. android 中fragment和activity的区别?
  5. android使用finish()和System.exit()退出
  6. Github android客户端源代码分析之一:环境
  7. Android日记 获取SharedPreferences三种
  8. cocos2dx android添加广点通广告平台的--
  9. Android Dialog全屏显示
  10. Windows平台上编译OpenCV的Android版本