Android Studio tips: Populating data with layout previews _android

Source: Internet
Author: User
Tags visibility

We all know that Android Studio is great, and the layout previews are great. When we tune the UI, we basically need a live preview to see the effect, we'll just have to switch to design in the Android studio, and we need to populate the layout with the data preview better, For example, we set the Text property in TextView to look at the font size and layout is correct, but the formal environment we need to remove these additional data, or look very uncomfortable, this time to use this blog introduced a technique.

Nonsense not much to say, directly above the figure:

In the example above, just add the Text property of the tools namespace to the XML layout file OK, this attribute is completely unrelated to the officially released version, isn't it cool?

Just need to add namespaces to the layout before it's OK

Copy Code code as follows:

<linearlayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
...

The usage is simple, just use the tools namespace instead of the Android namespace, so we can use
Copy Code code as follows:

<listview
Android:id= "@+id/listview"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:fastscrollalwaysvisible= "true"
Tools:fastscrollalwaysvisible= ""/>

You can also use this
Copy Code code as follows:

<button
Android:id= "@+id/button"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "a"
tools:visibility= "Invisible"/>

<button
Android:id= "@+id/button2"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Second"
tools:visibility= "Visible"/>


Note that the Tools property can only be used in the layout file and can only use some of the properties that the framework takes, and that you cannot use custom attributes, but that's enough to basically meet our needs.

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.