Android xmlns: tools usage

Source: Internet
Author: User

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
      • They do not appear as an option in for example the layout editor property sheet.
      • Editor code completion does not help you enter these attributes; the easiest way to use them is to first enter them in the Android namespace, and when done replacing the prefix. currently, this part can only be manually entered, and Automatic Code filling cannot be completed.
      • Note that designtime attributes are supported only for layout files themselves. you cannot use them anywhere else -- in menu XML files, in string resource definitions, etc. only layout is supported, and menu/resource/string is not supported currently. This statement is in conflict with the content in http://tools.android.com/tech-docs/tools-attributes, and tools-attributesis in conflict. All And Content
      • Designtime attributes can only be used for framework resources, not custom attributes at this point. It can only be applied to the attributes provided by the system. custom attributes are not in this range.
      • See https://code.google.com/p/android/issues/detail? Id = 46186 for background or additional requests or comments.

         

        Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.