打嗝的活动转变与共享的元素 [英] Hiccups in activity transitions with shared elements

查看:110
本文介绍了打嗝的活动转变与共享的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Android的棒棒堂的新的活动转变。但目前我看到很奇怪的hickups在动画。我砍死在一起最小的样本,我能想到的。

这是我在很短的版本做的:

  1. 在启用窗口内容转换我的 styles.xml
  2. 引用的一个非常简单的 slide.xml 在我的风格退出转换
  3. 提供一个安卓transitionName 在这两个布局共享的元素
  4. 名为 ActivityOptions.makeSceneTransitionAnimation()这个名字,我想分享的观点
  5. 传递所产生的束 startActivity()

这是我看到的行为(尽量慢10倍动画速度,看看我的意思): 右前的幻灯片动画滑下未共享的观点,这些观点跳了下去一点。他们居然动了一下分开。

不过:这仅发生在第二的时候,我运行动画(事后每次)。第一遍看就好了。而也这只是发生如果我想与大家分享下一个活动的元素。一切工作正常,如果我不尝试共享的元素。

下面是我的code:

值/ styles.xml

<资源> <样式名称=AppTheme父=机器人:Theme.Material.Light>     <! - 使窗口的内容转换 - >     <项目名称=机器人:windowContentTransitions>真< /项目>     <! - 指定退出转换 - >     <项目名称=机器人:windowExitTransition> @转换/幻灯片< /项目> < /风格> < /资源>

过渡/ slide.xml

<滑动/>

布局的主要活动

< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android     机器人:layout_width =match_parent     机器人:layout_height =match_parent>     <的LinearLayout         机器人:layout_width =match_parent         机器人:layout_height =match_parent         机器人:方向=垂直>         <查看             机器人:layout_width =match_parent             机器人:layout_height =0dp             机器人:layout_weight =1             机器人:后台=#0000FF/>         <查看             机器人:layout_width =match_parent             机器人:layout_height =0dp             机器人:layout_weight =1             机器人:后台=#00FF00/>         <查看             机器人:layout_width =match_parent             机器人:layout_height =0dp             机器人:layout_weight =1             机器人:后台=#0000FF/>         <查看             机器人:layout_width =match_parent             机器人:layout_height =0dp             机器人:layout_weight =1             机器人:后台=#00FF00/>     < / LinearLayout中>     <! - 实际的元素,我想分享 - >     <查看         机器人:ID =@ + ID /视图         机器人:layout_width =56dp         机器人:layout_height =56dp         机器人:后台=#FF0000         机器人:海拔=8DP         机器人:transitionName =查看/> < / RelativeLayout的>

MainActivity.java

公共类MainActivity扩展活动实现View.OnClickListener {     查看MView的;     @覆盖     保护无效的onCreate(包savedInstanceState){         super.onCreate(savedInstanceState);         的setContentView(R.layout.activity_main);         MVIEW = findViewById(R.id.view);         mView.setOnClickListener(本);     }     @覆盖     公共无效的onClick(视图查看){         ActivityOptions选项= ActivityOptions.makeSceneTransitionAnimation(这一点,MVIEW,意见);         意向意图=新的意图(这一点,SecondaryActivity.class);         startActivity(意向,options.toBundle());     } }

解决方案

这可能是你打的是,由于某种原因,没有发现L的锁定后,直到过渡库中的缺陷。

在这个bug,你必须有一个重新输入转换和共享的元素重新输入过渡。默认再输入过渡是一样的两个出口过渡

如果,返回过渡期间,所述共享单元被传回调用活动而次仍然进入,将看到一个打嗝时它将中断返回呼叫。随着幻灯片和爆炸过渡,你也将看到下一次退出,他们会从哪里打嗝发生开始,所以你得到一个不错的双wammy。

所以,你有几种选择来解决此错误,直到MR1:

  • 精确设置安卓windowSharedElementReenterTransition @null 。大多数时候,你并不需要一个共享的元素重新输入过渡,因为所谓的活动将会把共享元素在正确的位置给你。
  • 请不要使用退出转换(集安卓windowReenterTransition @null
  • 确保呼叫活动的 Android的持续时间:windowSharedElementReturnTransition 足够大,以便调用活动的 windowReenterTransition 完成第一。这可能是棘手的,因为它可以取决于设备的状态。 - 主叫活性可能已被从内存中删除,并需要重新启动
  • 设置安卓windowAllowReturnTransitionOverlap

I want to use the new Activity Transitions of Android Lollipop. But currently I am seeing very weird hickups during the animations. I hacked together the smallest sample I could think of.

This is what I did in a very short version:

  1. Enabled window content transitions in my styles.xml
  2. Referenced a very simple slide.xml as exit transition in my style
  3. Provided a android:transitionName for a shared element in both layouts
  4. Called ActivityOptions.makeSceneTransitionAnimation() with that name and the view I want to share
  5. Passed the resulting bundle to startActivity()

This is the behavior I see (try 10x slower animation speed to see what I mean): Right before the slide animation slides down the views that are not shared, those views jump down a little. They actually move a little apart.

But: This only happens the second time I run that animation (and every time afterwards). The first pass looks just fine. And also this only happens if I want to share an element with the next activity. Everything works fine if I don't try to share an element.

Here is my code:

values/styles.xml

<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
    <!-- enable window content transitions -->
    <item name="android:windowContentTransitions">true</item>

    <!-- specify exit transition -->
    <item name="android:windowExitTransition">@transition/slide</item>
</style>
</resources>

transition/slide.xml

<slide />

Layout for the main activity

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#0000ff" />

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#00ff00" />

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#0000ff" />

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#00ff00" />

    </LinearLayout>

    <!-- the actual element I want to share -->
    <View
        android:id="@+id/view"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:background="#ff0000"
        android:elevation="8dp"
        android:transitionName="view" />

</RelativeLayout>

MainActivity.java

public class MainActivity extends Activity implements View.OnClickListener {

    View mView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mView = findViewById(R.id.view);
        mView.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, mView, "view");

        Intent intent = new Intent(this, SecondaryActivity.class);
        startActivity(intent, options.toBundle());
    }


}

解决方案

It is possible that you are hitting a bug in the transitions library that, for some reason, wasn't discovered until after L was locked down.

In the bug, you must have a reenter transition and a shared element reenter transition. The default reenter transition is the same as the exit transition for both.

If, during the return transition, the shared element is transferred back to the calling Activity while the views are still entering, you will see a hiccup when it interrupts the return call. With the slide and explode transitions, you will also see that the next time you exit, they will start from where the hiccup happened, so you get a nice double-wammy.

So you have a few options to work around this bug until MR1:

  • Explicitly set the android:windowSharedElementReenterTransition to @null. Most of the time you don't need a shared element reenter transition because the called Activity will place the shared element in the right location for you.
  • Don't use an exit transition (set android:windowReenterTransition to @null)
  • Make sure the duration of the calling Activity's android:windowSharedElementReturnTransition is large enough so that the calling Activity's windowReenterTransition finishes first. This can be tricky because it can depend on device state -- the calling Activity may have been removed from memory and need to be restarted.
  • Set android:windowAllowReturnTransitionOverlap to false.

这篇关于打嗝的活动转变与共享的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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