分享:android之hardwareAccelerated你不知道的一些问题
来源:互联网 发布:2016年淘宝9月大促时间 编辑:程序博客网 时间:2024/05/29 01:53
在Android中,可以四给不同层次上开启硬件加速:
1、Application
<applicationandroid:hardwareAccelerated="true">
2、Activity
<activityandroid:hardwareAccelerated="true">
3、Window
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
4、View
view.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
在这四个层次中,应用和Activity是可以选择的,Window只能打开,View只能关闭。
在apk的AndroidManifest中,如果指定了minSDKVersion&targetSDKVersion=7,会使得应用无法使用硬件加速进行绘图。
注:有些朋友可能会遇到在开发过程中用到虚线的情况,实现有两种方式:
方式一:
hundsun_include_dotted_line.xml
<?xml version="1.0"encoding="utf-8"?>
<Viewxmlns:android="http://schemas.android.com/apk/res/android"
style="@style/HundsunStyleWmHw"
android:background="@drawable/hundsun_shape_dotted_line" />
hundsun_shape_dotted_line.xml
<?xml version="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<!-- 显示一条虚线,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线(使用时需要把这个Activity的硬件加速关了) -->
<stroke
android:dashGap="@dimen/hundsun_dimen_wee_spacing"
android:dashWidth="@dimen/hundsun_dimen_small_spacing"
android:width="@dimen/hundsun_dimen_normal_divide"
android:color="@color/hundsun_app_color_divide" />
<!-- 虚线高度 -->
<size android:height="2dp" />
</shape>
这种方式需要在使用该虚线的Activity中设置<activity android:hardwareAccelerated="false">,缺点是这个Activity会变慢,如果有网络请求时,大概率出现收到数据后不会回调问题(断点时,每次都会回调,这是很多人遇到的奇怪问题)。
方式二(建议使用这种方式):
hundsun_include_dash_line.xml
<?xml version="1.0"encoding="utf-8"?>
<Viewxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/hundsun_dimen_normal_divide"
android:background="@drawable/hundsun_shape_dash" />
hundsun_shape_dash.xml
<?xml version="1.0"encoding="utf-8"?>
<bitmapxmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/hundsun_dashed_line"
android:tileMode="repeat" />
hundsun_dashed_line.png是一张图片,只要很小很小就行,自动平铺的。另外对APP进行在线全方位的安全性、兼容性测试,我都会用这个:www.ineice.com。
- 分享:android之hardwareAccelerated你不知道的一些问题
- hardwareAccelerated你不知道的一些问题
- ImageView你不知道的一些问题
- android一些你知道的或不知道的style
- 还有一些你不知道的IT之事
- Android中一些你可能不太知道的东西
- Android Service中一些你不知道的细节
- 你不知道一些神奇Android Api
- 分享一些可能你不知道的shell用法和脚 本,简单&强大
- 一些你不知道的CSS属性
- Chrome一些你不知道的功能
- Android之50个你不知道的使用窍门
- android开发之你不知道的API-moveTaskToBack()
- 两个数学家的问题,“你不知道我不知道你知道我知道”
- 【Bugly干货分享】关于 Android N 那些你不知道的事儿
- 【Bugly干货分享】关于 Android N 那些你不知道的事儿
- 【Bugly干货分享】关于 Android N 那些你不知道的事儿
- Android开发中一些你需要知道的图片相关知识和网站推荐分享
- windows下安装python及django的开发环境
- 记一次处理日志文件过大问题的解决过程(SQL Server)
- MVN 核心总结1
- SQLite数据库增删改查操作案例
- php的密码加密password_hash
- 分享:android之hardwareAccelerated你不知道的一些问题
- 前端表单验证插件
- 初来乍到之辛酸菜鸟
- ubuntu chrome和中文输入法安装
- ios 属性和实例变量的区别
- Android GridView属性集合
- IntelliJ IDEA WEB项目的部署配置
- 让生命恢复纯净
- 2015年中国“互联网+”体育研究