与对话活动共用元件过渡 [英] Shared element transition with Dialog Activity

查看:203
本文介绍了与对话活动共用元件过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我组建了一个非常简单的应用程序开始,对话的主题活动时使用共享的元素转换(来源$ GitHub上 C $ C)。

I put together a very simple app that uses shared element transitions when starting an activity with Dialog theme (source code on github).

我得到了以下结果:

正如你可以看到有2个问题与过渡/动画:

As you can see there are 2 problems with the transition/animation:

  1. 动画是只是在对话活动,因此剪辑的区看到,而且长相丑陋。
  2. 在没有过渡/动画,当我挖掘活动外 回去。
  1. The animation is only visible in the area of the dialog activity so it clips and looks ugly.
  2. There is no transition/animation when I tap outside the activity to go back.

我该如何解决这些问题呢?任何帮助将是AP preciated。

How can I fix these problems? Any help would be appreciated.

编辑:后Quanturium的答案,我做了以下事情得到它的工作:

After Quanturium's answer I did the following things to get it working:

使用一个对话的主题以下主题改为:

Use the following theme instead of a Dialog theme:

<style name="AppTheme.Transparent" parent="AppTheme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

使用一个CardView为背景的对话框的外观和圆润的边角和阴影。

Use a CardView as the background for Dialog look and for rounded corners and shadows.

呼叫finishAfterTransition();当用户点击CardView之外。

Call finishAfterTransition(); when user taps outside the CardView.

现在它看起来像这样( code ),该CardView需要细化以便更好地匹配对话,但它至少工作:

Now it looks like this (code), the CardView needs refining to better match the Dialog, but it's working at least.:

推荐答案

这是活动的过渡是这样工作的。当你开始你的第二个活动,它会显示在你的第一个具有透明背景的顶部。共享单元被定位在相同的方式,他们是在第一活动,然后动画到第二活动指定的正确的位置。

An activity transition works like this. When you start your second activity, it is displayed on top of your first one with a transparent background. The shared elements are positioned the same way they are on the first activity and then animated to the correct position specified on the second activity.

在你的情况,你所使用的Andr​​oid版本:主题=@风格/ Theme.AppCompat.Dialog,这意味着第二个活动的绘图区域的大小比,从第一个活动之一小。这解释了裁剪和无外点击时的过渡。

In your case you are using android:theme="@style/Theme.AppCompat.Dialog" which mean the size of the second activity's drawing area is smaller than the one from the first activity. This explains the clipping and the no transition when clicking outside.

您想要做的是摆脱这一主题,贯彻,以便能够执行的平稳过渡自己的布局与深色背景/阴影什么。

What you want to do is get rid of that theme, and implement your own layout with a dark background / shadow in order to be able to execute your smooth transition.

这篇关于与对话活动共用元件过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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