Android 开发 Tip 15 -- can be replaced by one <TextView/> and a compound drawable

来源:互联网 发布:win10怎么连网络打印机 编辑:程序博客网 时间:2024/06/08 08:59

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/72526781


 This tag and its children can be replaced by one <TextView/> and a compound drawable

当xml布局文件中,出现两个紧挨着的 <ImageView /> <TextView />,IDE就会给出这样一个提示!

意思就是可以通过一个 <TextView /> 控件,然后设置 compound drawable 属性来替代完成!

比如:

<LinearLayout          android:orientation="horizontal"         android:layout_height="wrap_content"      android:layout_width="wrap_content">      <ImageView           android:src="@drawable/icon_add"        android:layout_width="wrap_content"          android:layout_height="wrap_content"/>      <TextView          android:layout_height="wrap_content"          android:layout_width="wrap_content"          android:text="@string/app_name"/>  </LinearLayout>  

可以替换成:

    <TextView          android:drawableLeft="@drawable/icon_add"        android drawablePadding="5dp"        android:layout_height="wrap_content"          android:layout_width="wrap_content"          android:text="@string/app_name"/>  

减少布局层级,减少测量布局绘制的耗时~

阅读全文
0 0
原创粉丝点击