按下概览按钮后,ZoomableDraweeView将被释放并重置

时间:2018-03-14 08:15:50

标签: android fresco

我有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()的调用?

1 个答案:

答案 0 :(得分:0)

虽然大部分状态都是由壁画自动保存和恢复的,但ZoomableController.transform: Matrix似乎不会自动管理。我通过在Activity.onPause()期间复制Matrix并在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()
    }
}