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

1、Application
<application android:hardwareAccelerated="true">

2、Activity
<activity android: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"?>

<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是一张图片,只要很小很小就行,自动平铺的

本文出自 “旦旦家园” 博客,谢绝转载!

更多相关文章

  1. android 打开 url 方式
  2. Android中自定义Dialog常用的两种方式
  3. Android创建和删除桌面快捷方式
  4. android之hardwareAccelerated你不知道的一些问题
  5. Android中创建和检测快捷方式
  6. Android边框背景
  7. Android(安卓)Studio 自动生成注释(作者、日期、联系方式、描述)
  8. 学习Android界面开发: Shape Drawable
  9. Android常用屏幕适配方式

随机推荐

  1. Xamarin.Android教程:模拟器选择
  2. android Service之一:不需和Activity交互
  3. Fragment、FragmentActivity 和Actvity区
  4. 【Android】快速切换到主线程更新UI的几
  5. Android仿百度地图小度语音助手的贝塞尔
  6. [置顶] android LayoutInflater、setCont
  7. 判断环境为iOS或Android
  8. Android开发中Activity属性设置小结
  9. android 使用 kotlin lambda 表达式,可以
  10. android 2.1 获取手机流量