Android 线性布局(LinearLayout)性能相关
2015-06-09 17:03
615 查看
Android 线性布局(LinearLayout)性能相关
太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)本文遵循“署名-非商业用途-保持一致”创作公用协议转载请保留此句:太阳火神的美丽人生 - 本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
如下嵌套线性布局中有两处性能问题,在不使用 Eclipse Adt 提示的情况下,你能找得出来吗?
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.mitest.linearlayoutexample.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_id="@+id/testLinearLayout02"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
下面揭晓答案:第一处:
使用布局宽度值 0dp 替换 wrap_content 会得到更好的性能;
第二处:
嵌套使用权重对性能有损害。
线性布局里面嵌套了一层线性布局,并且两层都使用了 weight 权重属性来分配布局内空间,如果出现这种情况,那么可能是界面布局考虑欠妥,我做的例子中,通过相对布局很好地解决了这个问题。
简而言之,能用相对布局替换的线性布局,应该就是可以避勉使用的线性布局,略有武断,但对未来扩展会留出很大空间,并且每一次界面布局的改变,最好都重新构思各种布局方式的使用。性能无小事,尤其对于 Android !
太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)本文遵循“署名-非商业用途-保持一致”创作公用协议转载请保留此句:太阳火神的美丽人生 - 本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
如下嵌套线性布局中有两处性能问题,在不使用 Eclipse Adt 提示的情况下,你能找得出来吗?
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.mitest.linearlayoutexample.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_id="@+id/testLinearLayout02"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
下面揭晓答案:第一处:
使用布局宽度值 0dp 替换 wrap_content 会得到更好的性能;
第二处:
嵌套使用权重对性能有损害。
线性布局里面嵌套了一层线性布局,并且两层都使用了 weight 权重属性来分配布局内空间,如果出现这种情况,那么可能是界面布局考虑欠妥,我做的例子中,通过相对布局很好地解决了这个问题。
简而言之,能用相对布局替换的线性布局,应该就是可以避勉使用的线性布局,略有武断,但对未来扩展会留出很大空间,并且每一次界面布局的改变,最好都重新构思各种布局方式的使用。性能无小事,尤其对于 Android !
相关文章推荐
- Android zxing二维码扫描 扫描框适应各种分辨率
- Android中自动跳转到系统设置界面
- android editText 软键盘enter键图标的设置
- android 反编译初级
- Android 4.1 systrace使用方法(一)
- android addr2line + objdump定位crash 问题
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.badlogic.androidgames.
- Android中使用代码截图的各种方法总结
- android 一些开源项目
- 初识Android遇到的小问题
- android:descendantFocusability用法简析
- Android总结之drawable(hdpi,mdpi,ldpi)文件夹的使用
- Android JNI 数据类型转换
- Android的onCreateOptionsMenu()创建菜单Menu详解
- 【Android】正确导入第三方jar包
- Android Studio开发入门-引用jar及so文件
- Android中Gridview和ViewPager显示图片的优化处理(2)
- Android 中compiledSDKVersion,minSdkVersion,targetSdkVersion的含义
- Android之ContentProvider使用
- Android中文API(129) —— AudioManager