Android View.invalidate(Rect) different behavior between two devices

纵饮孤独 提交于 2019-12-13 16:28:15

问题


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);
}

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

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


回答1:


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 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);


来源:https://stackoverflow.com/questions/29915690/android-view-invalidaterect-different-behavior-between-two-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!