分享:android之hardwareAccelerated你不知道的一些问题

Android中,可以四给不同层次上开启硬件加速:

1Application

<application android:hardwareAccelerated="true">

2Activity

<activity android:hardwareAccelerated="true">

3Window

getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

4View

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

在这四个层次中,应用和Activity是可以选择的,Window只能打开,View只能关闭。

 

apkAndroidManifest中,如果指定了minSDKVersion&targetSDKVersion=7,会使得应用无法使用硬件加速进行绘图。

 

注:有些朋友可能会遇到在开发过程中用到虚线的情况,实现有两种方式:

方式一:

hundsun_include_dotted_line.xml

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

<View xmlns: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"?>

<shape xmlns: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"?>

<View xmlns: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"?>

<bitmap xmlns: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

 


转载于:https://my.oschina.net/u/2455226/blog/541263

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值