我有一个com.facebook.samples.zoomable.ZoomableDraweeView活动。按下电话的overview button时,将调用onSaveInstanceState()方法,并且我正在存储DefaultZoomableController.transform值,以防需要重新创建视图。但是,如果我立即返回到我的应用程序,则不会调用onCreate(Bundle savedInstanceState),也没有要还原的转换值,但是ZoomableDraweeView已被重置为其初始状态。显然,如果不需要重新创建视图,则不会调用onCreate()

然后,ZoomableDraweeView不应返回其初始状态。我看到transform值在以下位置重置:

at com.facebook.samples.zoomable.DefaultZoomableController.reset(DefaultZoomableController.java:93)
at com.facebook.samples.zoomable.AbstractAnimatedZoomableController.reset(AbstractAnimatedZoomableController.java:44)
at com.facebook.samples.zoomable.DefaultZoomableController.setEnabled(DefaultZoomableController.java:108)
at com.facebook.samples.zoomable.ZoomableDraweeView.onRelease(ZoomableDraweeView.java:368)
at com.facebook.samples.zoomable.ZoomableDraweeView.access$100(ZoomableDraweeView.java:43)
at com.facebook.samples.zoomable.ZoomableDraweeView$1.onRelease(ZoomableDraweeView.java:69)
at com.facebook.drawee.controller.AbstractDraweeController.releaseFetch(AbstractDraweeController.java:193)
at com.facebook.drawee.controller.AbstractDraweeController.release(AbstractDraweeController.java:169)
at com.facebook.drawee.components.DeferredReleaser$1.run(DeferredReleaser.java:65)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Method.java:-1)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)


如何抑制对ZoomableDraweeView.onRelease()和/或DefaultZoomableController.reset()的调用?

最佳答案

尽管大多数状态是由壁画自动保存和恢复的,但ZoomableController.transform: Matrix似乎没有被自动管理。我通过在Activity.onPause()期间复制矩阵并在Activity.onResume()期间恢复矩阵来解决此问题。

对于example

class MainActivity {
    private var transform: Matrix = Matrix()

    override fun onResume() {
        super.onResume()
        defaultZoomableController.transform = transform
    }

    override fun onPause() {
        transform = Matrix(defaultZoomableController.transform)
        super.onPause()
    }
}

08-15 21:46