Android Performance(4) Overdraw

来源:互联网 发布:上海嘉定大数据公司 编辑:程序博客网 时间:2024/06/11 12:48

Android Performance(4) Overdraw

转载请注明:http://blog.csdn.net/liaoqianchuan00/article/details/23546533

概述

Overdraw就是你在某个界面上再画某些东西,比如你在一个LinerLayout上面添加一个TextView,那么TextView就是在LinerLayout上面再画了一次。Overdraw的存在是正常的,但是为了使我们的APP性能更好,我们要避免一些不必要的OverDraw。一般来说重画两次是正常的,意思就是说一个像素点被画了三次,但是如果重画更多次就应该被避免了。

 

使用

1.       进入设定->开发者选项->显示GPU过度渲染,打上勾。可以看见下面的文字(从最少到最多GPU用量:蓝,绿,浅红,红)。

 

2.       表格

 

没有颜色

没有overdraw

蓝色

1x overdraw

绿色

2x overdraw

浅红

3x,这可能就存在问题了,如果只是很小的区域,可以忽略

4x,像素点被画了5次或者更多,有问题

 

 

例子

1.       以下是我的ListView中某一行的布局。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

android:layout_height="?android:attr/listPreferredItemHeight"

android:background="@android:color/white"

 

   android:orientation="horizontal" >

 

   <LinearLayout

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:background="@android:color/white"

       android:orientation="vertical" >

 

       <LinearLayout

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:background="@android:color/white"

           android:orientation="vertical" >

 

           <TextView

               android:id="@+id/textView1"

                android:layout_width="wrap_content"

               android:layout_height="wrap_content"

               android:text="Entry"

               android:textAppearance="?android:attr/textAppearanceListItem"/>

 

           <TextView

               android:id="@+id/textView2"

               android:layout_width="wrap_content"

               android:layout_height="wrap_content"

               android:text="Stub"

               android:textAppearance="?android:attr/textAppearanceListItemSmall"/>

        </LinearLayout>

   </LinearLayout>

 

   <ImageView

       android:id="@+id/imageView1"

       android:layout_width="10dp"

       android:layout_height="?android:attr/listPreferredItemHeight"

       android:background="@android:color/black" />

 

    <TextView

       android:id="@+id/textView3"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_marginTop="20dp"

       android:text="Medium Text"

       android:textAppearance="?android:attr/textAppearanceMedium"/>

 

</LinearLayout>

2.       按照之前说的方法打开GPU过度渲染选项,运行程序

3.       可以得到这样的结果。可以看到布局文件的左侧部分是红色的,这个时候我们就应当注意我们的布局文件是否需要优化,可以结合之前文章中介绍的Hierarchy Viewer来分析。

 

参考

参考:http://www.vogella.com/tutorials/AndroidTools/article.html

 

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 剑灵启动游戏慢怎么办 网页页面结束进程也关不掉怎么办 开机就启动微信怎么办 微信突然无法启动怎么办 微信发送太频繁怎么办 微信在电脑上打不开文件怎么办 微信照片电脑上打不开怎么办 换一部手机微信怎么办 微信支付宝停止运行怎么办 剑三重制版卡顿怎么办 剑三客户端更新不动了怎么办 安装包安装失败怎么办有内存 qq飞车换手机了怎么办 qq飞车求婚失败戒指怎么办 改脸型皮肤会下垂怎么办 情侣关系弄僵了怎么办 用微信交话费没有到账怎么办 微信交错话费了怎么办 微信缴费交错了怎么办 微信支付被投诉怎么办 微信q币充值错误怎么办 微信充值流量充错了怎么办 微信延迟到账怎么办 移动流量充错了怎么办 qq充话费等待发货怎么办 qq充值话费没到账怎么办 电信话费冲错了怎么办 微信手机充错话费充空号怎么办 京东地址写错了怎么办 京东售后不退款怎么办 冲了话费不到账怎么办 币安维护充值怎么办 微信话费未到账怎么办 微信话费交错了怎么办 北京移动查话费余额怎么办 淘宝卖家客服无法联系怎么办? 微信支付月限额怎么办 微信超额20万怎么办 微信支付超额了怎么办 微信零钱超额了怎么办 微信的充值冲错了怎么办