Official android Technical Documentation translation-layout attribute during design, android Technical Documentation

Source: Internet
Author: User

Official android Technical Documentation translation-layout attribute during design, android Technical Documentation

This article is translated from the official androd technical document Designtime Layout Attributes: http://tools.android.com/tips/layout-designtime-attributes.

URL: http://blog.csdn.net/maosidiaoxian/article/details/42441269. Indicate the source for reprinting. If any translation error occurs, please correct it.


Layout rendering (layout preview window for layout editor and XML editor) is supported in Android Studio 0.2.11. Layout attribute during design.

These attributes are used for rendering in the tool but have no impact on the runtime. This is useful. For example, if you want to edit the Layout  Put the sample data in the text box, but these attributes do not affect your running applications.
To use design-Time Attributes, first make sure that you have a tool namespace defined in your layout:
<LinearLayout         xmlns:android="http://schemas.android.com/apk/res/android"          xmlns:tools="http://schemas.android.com/tools"         android:layout_width="match_parent"         ...
This tool namespace is a specialized namespace for Android tools. Therefore, you define all the attributes of tool-namespace on The View element, the application is automatically stripped when it is packaged and does not overhead the runtime.
Then, for example, set the text of the text field to use the same attributes as in the Android framework, but use tools:Namespace instead android:Namespace:
        <TextView              android:text="Name:"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />
        <EditText               tools:text="John Doe"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />
In the above example, the Name label uses the normal text attribute, which will be displayed at runtime. However, text fields use design-Time Attributes, so they appear in tools rather than at runtime.
Generally, you can set any Android framework attribute as the design-time attribute. tools:Namespace instead android:Namespace. Note that you do not have to select only one of them. You can set TwoAttributes, Android namespace attributes (used at runtime), and tool attributes (designed to overwrite runtime attributes ).
You can also use the design-time attribute in the tool DeleteThe value of an attribute. For example, there is such a bug (http:// B .android.com/58448) that you cannot use in the layout editor for ListView fastScrollAlwaysVisibleAttribute. However, you may still want this attribute to be set at runtime. You can solve this problem through design-time attributes:     <ListView         android:id="@+id/listView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:fastScrollAlwaysVisible="true"         tools:fastScrollAlwaysVisible=""/>
The following is another example. We have a FrameLayout with multiple sub-views, and we only want to see one of them during design, for example, the second one: we can use the tools: visibility 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" />(You may use visibility="gone"To replace visibility="invisible".) Restrictions
  • Currently, only existing attributes can be overwritten. We may need to define some additional convenient attributes to make it easier to select the child view displayed in ViewFlipper.
  • In this case, you must manually edit your design-time attributes.
    • They will not appear as an option, for example, in the layout editor Attribute Table.
    • The editor's Code Completion function does not help you access these attributes. The easiest way to use them is to first enter the Android namespace and then replace the prefix.
  • Note that the attribute only supports layout files during design. You cannot use them elsewhere-for example, in the menu XML file, in the string resource definition, and so on.
  • At this point, the attribute can only be used in Framework resources, but cannot be used in custom attributes.
  • View https://code.google.com/p/android/issues/detail? Id = 46186 to obtain background information, additional requests, or comments.
About tools:For more information about other Attributes of a namespace, see Tools Attributes.

Related Article

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.