《Android应用性能优化》 第8章 图形

1、例子中 30个部件的xml setContentView 几乎占用了从onCreate() 到 onResume() 结束之前所有时间的99%

因为展开布局的开销很大。要尽量用不同的布局方式。比如减少使用一层层嵌套的LinearLayout,使用ReltiveLayout将控件放在一层

减少创建对象的个数

2、Activity内容视图的“父亲”是一个FrameLayout。

因此当你的XML最顶层只是一个FrameLayout时,最终出现两个FrameLayout

此时可以使用<merge>合并这两个布局

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

  android:layout_width="fill_parent"

  android:layout_height="fill_parent"

  android:id="@+id/my_top_layout">

替换为:

<merge xmlns:android="http://schemas.android.com/apk/res/android">

3、使用<include>重用布局

4、ViewStub

<ViewStub

  android:id="@+id/mystubid"

  android:inflatedId="@+id/myid"

  android:layout="@layout/mylayout"/>

这时候布局 mylayout不会被setContentView展开

ViewStub stub = (ViewStub) findViewById(R.id.mystubid);

View inflatedView = stub.inflate();//inflatedView定义在mylayout.xml中

ViewStub view = (ViewStub) findViewById(R.id.mystubid);

view.setVisibility(View.VISIBLE);  //会把ViewStub在父容器中删除。替换为id为myid的布局

view = findViewById(R.id.myid);

5、布局工具

Android自带的工具,tools目录下:hierarchyviewer。

用了下,只能在模拟器中检查布局。真机需要root

http://blog.csdn.net/autumn_xl/article/details/40741835

[hierarchyviewer]Unable to get view server version from device 00856cd5d08d2409
[hierarchyviewer]Unable to get view server protocol version from device 00856cd5d08d2409
[ViewServerDevice]Unable to debug device: lge-nexus_4-00856cd5d08d2409
[hierarchyviewer]Missing forwarded port for 00856cd5d08d2409
[hierarchyviewer]Unable to get the focused window from device 00856cd5d08d2409

另一个layoutopt在tools下没找到

6、OpenGL

 找不到 RSSurfaceView

原文地址:https://www.cnblogs.com/maxiaodoubao/p/4428038.html