使用 DialogFragment 和 ScrollView 时共享元素过渡闪烁 [英] Shared element transition flicker when using DialogFragment and ScrollView

查看:42
本文介绍了使用 DialogFragment 和 ScrollView 时共享元素过渡闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

https://github.com/ulyssesp/SharedElementTransitions 上有一个重现.

这只会发生在有一个 DialogFragment 持有正在转换的 ImageView 时,而且它只是偶尔发生.当它发生时,如果图像不在 DialogFragment 的底部但仍然可见,那么您可以看到部分图像被正确渲染.感觉这是一种竞争条件,其中 DialogFragment 在 ImageView 之后(因此在其之上)呈现.

This only happens when there's a DialogFragment that holds the transitioning ImageView, and it only happens sometimes. When it does happen, if the image is off the bottom of the DialogFragment but still visible, then you can see part of the image being rendered correctly. It feels like it's a race condition where the DialogFragment gets rendered after (and therefore on top of) the ImageView.

我正在尝试在 DialogFragment 上的 ScrollView 中使用来自 ImageView 的共享元素转换,使用 Picasso 和缓存加载图片.每隔一段时间,当ScrollView 滚动时,进入过渡时会有闪烁.

I'm trying to use a shared element transition from an ImageView in a ScrollView on a DialogFragment using Picasso and a cache to load the image. Every once in a while when the ScrollView is scrolled, there is a flicker when entering the transition.

https://drive.google.com/file/d/0B9K_Hjcu9iFOV3lYNVB1UlpsNTQ/view?usp=sharing

最后一次点击上面的视频文件最能说明我在说什么.请注意,闪烁不会每次都发生,并且必须滚动滚动视图才能发生闪烁.实际项目中发生的事情还有很多,但这是重现错误的最小示例项目.

The last click on the video file above best shows what I'm talking about. Note that the flicker doesn't happen every time, and the scroll view has to be scrolled for the flicker to occur. There are a lot more things happening in the real project, but this is a minimal sample project to reproduce the bug.

相关代码:

styles.xml:

styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowSharedElementReenterTransition">@null</item>
    <item name="android:windowSharedElementExitTransition">@null</item>
</style>

ImageFragment::onCreateView:

ImageFragment::onCreateView:

...

mImageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        ActivityOptions activityOptions =
            ActivityOptions.makeSceneTransitionAnimation(getActivity(), v, "image");

        Intent i = new Intent(getActivity(), ImageDisplayActivity.class);
        i.putExtra("url", "http://i.imgur.com/DvpvklR.png");
        getActivity().startActivity(i, activityOptions.toBundle());
    }
});

new Picasso.Builder(getActivity())
    .memoryCache(MainActivity.sCache)
    .build()
    .load("http://i.imgur.com/DvpvklR.png")
    .into(mImageView);

...

图像显示活动:

...

mImageView.setImageBitmap(MainActivity.sCache.get(getIntent().getStringExtra("url") + "\n"));

如果您有任何见解或需要更多信息,请告诉我!

If you have any insights or need more information, let me know!

推荐答案

这看起来像是活动转换中的错误.即使没有共享元素退出转换也没有退出转换,我们还是将共享元素移动到 Window 的根覆盖层中.通常这不是问题,但是因为 DialogFragment 创建了一个对话框,它创建了一个新窗口,共享元素从对话框的窗口移动到 Activity 的窗口中!您可以看到共享元素暂时弹出对话框下方,然后在启动的 Activity 获取它后上升.

This looks like a bug in the Activity Transitions. Even though there is no shared element exit transition and no exit transition, we move the shared elements into the Window's root overlay. Normally this is not a problem, but because DialogFragment creates a dialog, which creates a new window, the shared element moves from the dialog's window into the Activity's window! you can see the shared element pop below the dialog temporarily and then rise above once the started Activity takes it.

最好能够通过将共享元素移动到正确的覆盖层来解决这个问题,而不仅仅是活动窗口的覆盖层.这样,如果您共享对话框和活动窗口中的元素,它们都会出现在正确的位置.

It would be ideal to be able to fix this by moving shared elements to the correct overlay, not just the Activity Window's overlay. That way if you share elements from the dialog AND the activity's windows, they all appear in the right place.

不过,就目前而言,这行不通.对不起.

For now, though, this is not going to work. Sorry.

这篇关于使用 DialogFragment 和 ScrollView 时共享元素过渡闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆