以前寫布局時為了觀看布局效果,會寫些靜態(tài)的測試數(shù)據(jù),以便在androidstudio中觀察布局的效果.等到寫完布局的時候在進行擦除.當布局很多的時候,這確實也是很費勁的事.其實官方早就為我們考慮到這點了.
我們在實際開發(fā)中可以使用tools.
tools可以覆蓋我們的屬性,但是運行時這些屬性是被忽略的
如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.xf.mylab.activity.AniTestActivity">
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"
tools:text="TEST"/><!--tools的屬性會直接在編輯中看到效果,而不會在運行時起效果-->
<Button
android:id="@+id/end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="end"
tools:text="TEST"/>
</LinearLayout>
as中預覽的效果:
實際運行時的效果:
tools對其他的屬性都是支持的,實際運用時只要把android:替換成tools:即可,不需要手動擦除,這對提高我們工作效率還是有幫助的.