美文网首页
Fresco 与 元素共享动画(Share Element Tr

Fresco 与 元素共享动画(Share Element Tr

作者: 恶童历险记 | 来源:发表于2017-08-29 15:00 被阅读423次

facebook的Fresco是我见过的Android上面最好的图片加载框架之一。但是用SimpleDraweeView来做Share Element Transition的时候出现了很多问题。

1.页面跳转的时候SimpleDraweeView不不显示图片

这个问题出现的比较早,facebook已经有解决方案了:
在跳转后的页面Activity加上这段代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setSharedElementEnterTransition(
                    DraweeTransition.createTransitionSet(ScalingUtils.ScaleType.CENTER_CROP,
                            ScalingUtils.ScaleType.CENTER_CROP)); // 进入
            getWindow().setSharedElementReturnTransition(
                    DraweeTransition.createTransitionSet(ScalingUtils.ScaleType.CENTER_CROP,
                            ScalingUtils.ScaleType.CENTER_CROP)); // 返回
}

2.Android 7.0以上返回跳转前页面完成过场动画之后SimpleDraweeView不显示图片

这个问题我尝试在onActivityResult里面进行监听检测是否SimpleDraweeView的状态被设为INVISIBLE或者GONE,并将其重新设置为VISIBLE但是并没有用。最后在Fresco的issue里面找到其他开发者提供的解决方案:
在跳转之前监听共享动画的结束回调,并将共享元素重新设置为可见

setExitSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames,
                                           List<View> sharedElements,
                                           List<View> sharedElementSnapshots) {

                super.onSharedElementEnd(sharedElementNames, sharedElements,
                        sharedElementSnapshots);

                for (View view : sharedElements) {
                    if (view instanceof SimpleDraweeView) {
                        view.setVisibility(View.VISIBLE);
                    }
                }
            }
        });

欢迎各位加入技术讨论群,一起论技术,侃大山。qq群:295456349

相关文章

网友评论

      本文标题:Fresco 与 元素共享动画(Share Element Tr

      本文链接:https://www.haomeiwen.com/subject/nxbodxtx.html