以前寫佈局時爲了觀看佈局效果,會寫些靜態的測試數據,以便在androidstudio中觀察佈局的效果.等到寫完佈局的時候在進行擦除.當佈局很多的時候,這確實也是很費勁的事.其實官方早就爲我們考慮到這點了.
我們在實際開發中可以使用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:即可,不需要手動擦除,這對提高我們工作效率還是有幫助的.