Android View.invalidate(Rect)两个设备之间的不同行为 [英] Android View.invalidate(Rect) different behavior between two devices

查看:191
本文介绍了Android View.invalidate(Rect)两个设备之间的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要与媒体播放器进度同步的自定义视图(波形).问题是使用invalidate(Rect)时我有不同的行为 这是在我的自定义视图中进行更新的代码:

I have a custom view (a Waveform) that needs to be synchronized with a media player progress. The problem is that I'm having a different behavior when using invalidate(Rect) Here is the code that makes the update in my custom view:

public void setProgress(int currentDuration) {
    // ... Some code to calculate the dirty width
    invalidate(mDirtyWidth,0,mDirtyWidth+ mDirtyWidthRegion, viewHeight);
}

这在Samsung Galaxy 4(Android 4.4.2)上完美运行. 启用了显示GPU视图更新"的屏幕截图

This is working perfectly on a Samsung Galaxy 4 (Android 4.4.2). Screenshot with "Show GPU view updates" enabled

但是在Nexus 7(Android 5.1)中,每次都会使整个视图无效:

But in a Nexus 7 (Android 5.1), the whole view gets invalidated each time:

推荐答案

在Android 5.0之后,canvas clipBounds始终是您与hardwareAccelerated的视图边界,invalidate(dirty rect)的脏矩形将被忽略

After Android 5.0, the canvas clipBounds always is your view bounds with hardwareAccelerated, the invalidate(dirty rect)'s dirty rect is ignored

5.0 ViewRootImpl.java

5.0 ViewRootImpl.java http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/android/view/ViewRootImpl.java/

            dirty.setEmpty();
            mBlockResizeBuffer = false;
            mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this);

4.4 ViewRootImpl.java http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.4.2_r1/android/view/ViewRootImpl.java/?v=source

4.4 ViewRootImpl.java http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.4.2_r1/android/view/ViewRootImpl.java/?v=source

            mCurrentDirty.set(dirty);
            dirty.setEmpty();
            attachInfo.mHardwareRenderer.draw(mView, attachInfo, this,
                    animating ? null : mCurrentDirty);

这篇关于Android View.invalidate(Rect)两个设备之间的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆