在android studio开发中,关于绘制GifView异常,硬件加速问题的解决办法
2016-09-22 16:07
302 查看
Hardware Acceleration硬件加速
关于绘制GifView异常:
我的处理方式是:
Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline is designed to better support hardware acceleration. Hardware acceleration carries out all drawing operations that are performed on a View’s canvas using the GPU. Because of the increased resources required to enable hardware acceleration, your app will consume more RAM.
Application level
In your Android manifest file, add the following attribute to the tag to enable hardware acceleration for your entire application:
Activity level
If your application does not behave properly with hardware acceleration turned on globally, you can control it for individual activities as well. To enable or disable hardware acceleration at the activity level, you can use the android:hardwareAccelerated attribute for the element. The following example enables hardware acceleration for the entire application but disables it for one activity:
`
如果您的应用程序不正确的行为和硬件加速全球打开,你可以控制它对个人Activity。启用或禁用硬件加速在活动级别,您可以使用android:hardwareAccelerated 元素的属性。下面的例子启用硬件加速整个应用程序,但禁用这一活动:
Window level
If you need even more fine-grained control, you can enable hardware acceleration for a given window with the following code:
如果你需要更准确的控制,您可以启用硬件加速对于一个给定的窗口下面的代码:
View level
You can disable hardware acceleration for an individual view at runtime with the following code:
关于绘制GifView异常:
09-22 16:09:50.769 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.779 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.779 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.779 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.789 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.789 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.789 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.799 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.799 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.xxx.gifview.MainActivity.access$super 'android.view.SearchEvent', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.809 10394-10394/com.example.xxx.gifview 4000 E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.xxx.gifview.MainActivity.access$super 09-22 16:09:50.859 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 09-22 16:09:50.889 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.view.ViewOutlineProvider', referenced from method com.example.xxx.gifview.view.GifView.access$super 09-22 16:09:50.889 10394-10394/com.example.xxx.gifview E/dalvikvm: Could not find class 'android.animation.StateListAnimator', referenced from method
我的处理方式是:
public GifView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); resources = context.getResources(); //android 4.0硬件加 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // 从描述文件中读出gif的值,创建出Movie实例 TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView); int resourceId = array.getResourceId(R.styleable.GifView_src, -1); setGifResource(resourceId); array.recycle(); }
Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline is designed to better support hardware acceleration. Hardware acceleration carries out all drawing operations that are performed on a View’s canvas using the GPU. Because of the increased resources required to enable hardware acceleration, your app will consume more RAM.
根据官网翻译可得:从Android 3.0(API级别11)开始,Android 2 d渲染管道是为了更好地支持硬件加速。硬件加速进行的所有绘图操作上执行一个视图使用GPU的画布。因为增加的资源需要启用硬件加速,你的应用将会消耗更多的内存。
The easiest way to enable hardware acceleration is to turn it on globally for your entire application. If your application uses only standard views and Drawables, turning it on globally should not cause any adverse drawing effects. However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your applications that use custom views or drawing calls. Problems usually manifest themselves as invisible elements, exceptions, or wrongly rendered pixels. To remedy this, Android gives you the option to enable or disable hardware acceleration at the following levels: - Application - Activity - Window - View > 启用硬件加速的最简单方法是将全局整个应用程序。如果您的应用程序只使用标准视图和画板,把它在全局范围内不应造成任何不良影响。然而,由于不支持硬件加速的2D 绘图操作,将其在可能会影响你的一些使用自定义视图或绘制调用的应用程序。问题通常表现为无形的元素、异常或错误地显示像素。为了补救,Android给你选择启用或禁用硬件加速在以下级别: 1.Application 2. Activity 3. Window 4. View ---------- Controlling Hardware Acceleration
Application level
In your Android manifest file, add the following attribute to the tag to enable hardware acceleration for your entire application:
应用程序级别 在你的Android清单文件中,添加以下属性的<应用>标记为您的整个应用程序启用硬件加速: <application android:hardwareAccelerated="true" ...>
Activity level
If your application does not behave properly with hardware acceleration turned on globally, you can control it for individual activities as well. To enable or disable hardware acceleration at the activity level, you can use the android:hardwareAccelerated attribute for the element. The following example enables hardware acceleration for the entire application but disables it for one activity:
`
如果您的应用程序不正确的行为和硬件加速全球打开,你可以控制它对个人Activity。启用或禁用硬件加速在活动级别,您可以使用android:hardwareAccelerated 元素的属性。下面的例子启用硬件加速整个应用程序,但禁用这一活动:
<application android:hardwareAccelerated="true"> <activity ... /> <activity android:hardwareAccelerated="false" /> </application>
Window level
If you need even more fine-grained control, you can enable hardware acceleration for a given window with the following code:
如果你需要更准确的控制,您可以启用硬件加速对于一个给定的窗口下面的代码:
getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
View level
You can disable hardware acceleration for an individual view at runtime with the following code:
你可以禁用硬件加速单个视图在运行时使用以下代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB { setLayerType(View.LAYER_TYPE_SOFTWARE, null); }
相关文章推荐
- 关于无法加载DLL"***.dll":找不到指定的模块(异常来自HRESULT:0x8007007E)问题的解决办法
- 关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法
- android开发中解决VideoView显示尺寸异常的问题
- 关于AutoCompleteTextView 为什么必须输入两个字符才能出现补全提示的问题的解决办法
- 关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法
- 关于TableView的cell重用问题解决办法
- 关于C#开发WEB项目TextBox控件的自适应高问题解决办法!
- 关于jFinal开发中遇到的中文乱码问题解决办法
- iOS开发 关于tableView加载图片时出现卡顿时的解决办法
- 关于BadgeView遇到的一个奇怪的问题和解决办法
- 关于AutoCompleteTextView 为什么必须输入两个字符才能出现补全提示的问题的解决办法
- ANDROID初探 关于android studio配置模拟器的一些问题跟解决办法
- 关于android开发遇到的一些问题的解决办法---间断的更新
- Android开发中关于Movie导入GIF图片异常的问题
- 在SurfaceView中绘制文本时 无法自动换行问题的解决办法
- 关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法
- 关于Android Studio替换为同名图片后,运行报错问题解决办法
- binbinyang---关于开发中listview 跟ScrollView 的冲突问题解决办法
- 【游戏开发备注之一】关于Cocos2dx_v1.x版本iphone与Android运行出现图片白块、添加GameCenter报错问题及编译Android闪退的解决办法&&CCLOG与CClog的区别
- 关于android开发时,发生Error infalting classa com.baidu.mapapi.map.MapView的解决办法