Android xmlns: tools usage
In Android development, the layout file contains the following content:
Xmlns: tools = "http://schemas.android.com/tools"
Android: orientation = "vertical"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Tools: context = ". MainActivity"
/>
What is the role of tools? Refer to document http://tools.android.com/tech-docs/tools-attributes
This document lists many tools methods, such as tools: ignore/tools: targetApi/tools: locale, but what we want to discuss today is the most detailed content in this document, Designtime Attributes, which is a http://tools.android.com/tips/layout-designtime-attributes.
These are attributes which are used when the layout is rendered inthe tool, but have no impact on the runtime. this is useful if you for examplewant 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.
These attributes are used to render the layout without affecting the program running. That is to say, this attribute only appears during preview layout and does not exist when the program is running.
This description is very interesting. For example, when we want to display a piece of text in the layout file, the text content may change dynamically in the program, in particular, the content of the string with parameters such as % 1 $ s must be displayed in android: text before, then adjust the size and color parameters of the text, and then delete the android: text attribute. With the tools parameter, you can directly use tools: text to display the text during preview, saving the trouble of deleting it.
Commonly used tools: text, tools: visibility, tools. src, tools. background
Some restrictions are also listed in the official documents as follows:
- Currently only overriding existing attributes is supported. we may want to define some additional convenience attributes to make it simple to for example choose which child in a ViewFlipper to show etc. currently, only existing attributes of overriding are supported.
- You have to manually edit in your designtime attributes at this time