Android View.invalidate(Rect)两个设备之间的不同行为

时间:2015-04-28 09:37:33

标签: android android-canvas android-view

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

'sphoto_categories' => '["3"]'

这在三星Galaxy 4(Android 4.4.2)上完美运行。 屏幕截图显示"显示GPU视图更新"启用

enter image description here

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

1 个答案:

答案 0 :(得分:3)

在Android 5.0之后,canvas canvasBounds总是你的视图边界与hardwareAccelerated,无效(脏rect)的脏rect被忽略

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

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