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.