Transitions of various android views


please I need help with transitions. in my activity_main2.xml I have two views one is a ImageView and another one FloatingActionButton what I want is that when I enter activity 2 from my activity 1 I do it with animation but separated osea the ImageView that enters with start and the FloatingActionButton that enters with Top so separately I have this trasition in my res and even then I move all together.

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android=""
    <slide android:slideEdge="start">
            <target android:targetId="@id/imagenPortada" />
    <slide android:slideEdge="top">
            <target android:targetId="@id/fab" />

And this is my style where I define and activate my transitions

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#E21E63</item>
    <item name="colorPrimaryDark">#C2145B</item>
    <item name="colorAccent">#FFFFFF</item>
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowEnterTransition">@transition/transition</item>
    <item name="android:windowExitTransition">@transition/etransition</item>

It's more or less what I want to achieve but in this case only with the floatingButton and the portda

asked by Gunnar 23.03.2016 в 13:49

1 answer


The problem is that you are using a TransitionManager , in order to move the elements separately, what you are using is to animate two layouts!

In this case when you start "activity 2" you could simply use ObjectAnimator to control the translation of the elements, for example if you want an animation of your image from top to bottom you can do it with:

ObjectAnimator animX = ObjectAnimator.ofFloat(imagenPortada, "x", 0f);
ObjectAnimator animY = ObjectAnimator.ofFloat(imagenPortada, "y", 1000f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);

more information Animating Views (English)

answered by 23.03.2016 / 23:49