简体   繁体   English

如何在共享元素转换后使用动画

[英]How to use animation after shared element transition

i'm use shared element transtion go to activity2 and in activity2 the transtion is not working 我使用共享元素转换转到activity2,在activity2中转换不起作用

ttb = AnimationUtils.loadAnimation(this, R.anim.ttb_animation);
slogan = findViewById(R.id.slogan);
slogan.startAnimation(ttb);

i try to use delay with handler its work, but i dont need it. 我尝试使用延迟与处理程序的工作,但我不需要它。

Intent goto_activity2 = new Intent(SplashAct.this, Activity2.class);
            ActivityOptionsCompat option = ActivityOptionsCompat
                    .makeSceneTransitionAnimation(SplashAct.this, app_logo, ViewCompat.getTransitionName(app_logo));
            startActivity(goto_activity2, option.toBundle());
            finish();

xml code xml代码

    <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="800"
    android:startOffset="100"
    android:interpolator="@android:anim/accelerate_interpolator"
    >

    <translate
        android:fromYDelta="350"
        android:toYDelta="0"
        />

    <scale
        android:fromXScale="1.2"
        android:fromYScale="1.2"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0"
        />

</set>

transition in activity2 is not working activity2中的转换不起作用

For shared element transition you need to provide same transtionName to the respective view in both the acitivties. 对于共享元素转换,您需要在两个acitivties中为相应视图提供相同的transtionName。 In Activity A , suppose youhave a image view 在活动A中,假设您有一个图像视图

 <ImageView
      android:id="@+id/ivImage"
      android:transitionName="transitionName"
      android:scaleType="centerCrop"
      android:layout_width="match_parent"
      android:layout_height="160dp" />

and in your activity B : 在你的活动B中:

 <ImageView
      android:id="@+id/ivSenderImage"
      android:transitionName="transitionName"
      android:scaleType="centerCrop"
      android:layout_width="match_parent"
      android:layout_height="160dp" />

Then while navigating to another activity , all you hav to do is : 然后在导航到另一个活动时,您要做的就是:

Intent intent = new Intent(AcitvityA.this, ActivityB.class);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, (View)ivImage, "transitionName");
startActivity(intent, options.toBundle());

Thats all , with the transition name ensures that even if you have multiple views with the same transition name in the source hierarchy, it will essentially be able to pick the right view to start the animation from. 总而言之,使用转换名称可确保即使您在源层次结构中有多个具有相同转换名称的视图,它也基本上能够选择正确的视图来启动动画。

Or you can check this too https://medium.com/@aitorvs/android-shared-element-transitions-for-all-b90e9361507d . 或者您也可以查看这个https://medium.com/@aitorvs/android-shared-element-transitions-for-all-b90e9361507d and https://android-developers.googleblog.com/2018/02/continuous-shared-element-transitions.html https://android-developers.googleblog.com/2018/02/continuous-shared-element-transitions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM