您的位置:首页 > 移动开发 > Android开发

android tools小应用

2016-05-05 16:25 435 查看
TextView在xml中没有设置任何字符,而是在activity中设置了text。因此为了在ide中预览效果,你必须在xml中为TextView控件设置android:text属性

<span style="font-size:18px;"><span style="font-size:18px;"><TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
 android:text="这是textview"/></span></span>
一般我们在这样做的时候都告诉自己,没关系,等写完代码我就把这些东西一并删了。但是你可能会忘,以至于在你的最终产品中也会有这样的代码。别傻了,你肯定会忘的。没关系,小编教你一招,屡试不爽。
我们在生成xml文件时总会自动生成

<span style="font-size:18px;"> xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"</span>
这两行代码,tools可以告诉Android Studio,哪些属性在运行的时候是被忽略的,只在设计布局的时候有效。比如我们要让android:text属性只在布局预览中有效可以这样
<span style="font-size:18px;"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
tools:text="这是textView"/></span>
tools可以覆盖android的所有标准属性,将android:换成tools:即可。同时在运行的时候就连tools:本身都是被忽略的,不会被带进apk中。这只是tools的简单应用。用了tools,领导再也不会担心你的工作了!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android xml textview tools