平时在写资源XMl文件的时候,经常看到的前缀都是android:或者是tools:。
当然你在引用这两个前缀的时候需要导入其命名空间(Namespace)。
例如下面这个例子:

在该例子中我使用了android:前缀,但是未导入其命名空间,导致报错,只用加上这句话就可以恢复正确:
xmlns:android=”http://schemas.android.com/apk/res/android”
当然类似,如果你引用tools:前缀,那你也需要导入tools的命名空间:
xmlns:tools=”http://schemas.android.com/tools”

官网:http://tools.android.com/tech-docs/tools-attributes
http://tools.android.com/tips/layout-designtime-attributes

As of Android Studio 0.2.11, the layout rendering (used in both the layout editor as well as the XML editor layout preview window), supports designtime layout attributes.
These are attributes which are used when the layout is rendered in the tool, but have no impact on the runtime. This is useful if you for example want to put sample data in your textfields for when you are editing the layout, but you don’t want those attributes to affect your running app.

Android XMl文件中tools前缀_第1张图片

The tools namespace is a specially recognized namespace by the Android tools, so all the attributes you define on view elements in the tools-namespace will be automatically stripped when the application is packaged and there is no runtime overhead.

Usage:

  • android: -> tools:
  • Can both set Android namespace attribute and tools attribute

例如:

 <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="First"        tools:visibility="invisible" /><Button        android:id="@+id/button2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Second"        tools:visibility="visible" />

Limitations:

  • Can only overriding existing attributes
  • No option and no code completion(u can replace the prefix)
  • Only support framework resources, no custom attributes

Other Usage?

tools:ignore –- 告诉Lint忽略xml中的一些警告

<ImageView  android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/divider" />

Warning: Missing contentDescription attribute on image.
Solution: tools:ignore=”contentDescription”

tools:targetApi – minSdkLevel:15, but u need the widgets in high API level

<ripple xmlns:android="http://schemas.android.com/apk/res/android"  android:color="@color/accent_color" />

Solution: tools:targetApi =“LOLLIPOP”

tools:locale – undo spell checking in res/values/strings.xml

<resources  xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:locale="it">  <!-- Your strings go here --></resources>

tools:listitem;tools:listheader;tools:listfooter

<ListView    android:layout_width="fill_parent"    android:layout_height="wrap_content"    tools:listheader="@layout/epaysdk_view_payments_header"    tools:listitem="@layout/epaysdk_item_payments_usable"    tools:listfooter="@layout/epaysdk_view_payments_footer"/>

Android XMl文件中tools前缀_第2张图片

tools:showIn

公共部分layout:titlebar.xml
引用公共部分的layout:paysms.xml、payshorty.xml、paypwd.xml

在公共部分最顶端的layout中指明其中一个被包含的layout:
tools:showIn=”@layout/frag_paysms”

更多相关文章

  1. android中读写sd卡文件
  2. Android 支持的文件类型
  3. Android下载文本文件和mp3文件
  4. android project 文件夹
  5. Android 多国语言文件夹
  6. android shape用法(xml文件)
  7. android文件关联之mime type
  8. ubuntu共享文件夹设置
  9. android文件读取

随机推荐

  1. 个人简历制作——Android自动升级&个人“
  2. Galaxy S II vs HTC Sensation XE vs 小
  3. Android(安卓)中右上角菜单创建(Menu)
  4. 详解android的号码匹配
  5. Android(安卓)性能优化杂谈(开篇)
  6. Android破解锁屏密码(已root)
  7. Android(安卓)studio和Eclipse分别生成ja
  8. 打造通用的Android下拉刷新组件(适用于Li
  9. Android异步消息处理机制 深入理解Looper
  10. webView程序 第一次加载页面是出现白屏或