Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Activity/Fragment Transitions compatible with pre-Lollipop devices?

I'm trying to make an Activity Transition using Shared Elements on a pre-Lollipop device (4.x). Is it possible? So far, I'm trying this:

public class RewardDetail extends ActionBarActivity {
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        ...

        ViewCompat.setTransitionName(imageView, TRANSITION_NAME);
    }

    ...

    public static void launch(ActionBarActivity activity, View transitionView, WelcomeReward detailData) {
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionView, TRANSITION_NAME);
        Intent intent = new Intent(activity, RewardDetail.class);
        intent.putExtra(PARAM_DATA, detailData);
        ActivityCompat.startActivity(activity, intent, options.toBundle());
    }
}

called by:

@Override
public void onClick(final View v) {
    int position = recyclerView.getChildPosition(v);
    WelcomeReward welcomeReward = data.get(position);
    RewardDetail.launch(WelcomeRewardActivity.this, v.findViewById(R.id.reward_view), welcomeReward);
}

But it results in a "regular" transition (no shared element). Any ideas?

EDIT

According to this video, it could be done:

https://www.youtube.com/watch?v=RhiPJByIMrM&index=8&list=WL

Is there a library already implementing this for pre Lollipop ?

like image 689
Cheborra Avatar asked Oct 25 '14 21:10

Cheborra


People also ask

How do you animate fragment transitions?

At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.

How do you animate a fragment?

To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the Fragment Manager to create a Fragment Transaction . Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used).

What is transition in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


3 Answers

No, Activity/Fragment Transitions are not possible on pre-Lollipop devices. According to the documentation:

Start an activity with additional launch information, if able.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with ActivityOptionsCompat to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

See also George Mount's answer to this StackOverflow question.

like image 97
Alex Lockwood Avatar answered Oct 09 '22 03:10

Alex Lockwood


You can check out this library for activity and fragment transitions for pre lollipop devices

dependencies {
        compile 'com.albinmathew:PreLollipopTransition:1.1.2'
}

https://github.com/albinmathew/PreLollipopTransition

like image 44
Albin Mathew Avatar answered Oct 09 '22 03:10

Albin Mathew


Although the fancy Lollipop Activity/Fragment transitions are not available pre-Lollipop (without the use of a 3rd party library), you can still override the animation used to transition between activities.

Just before/after you start invoke startActivity() you can make a call to [Activity.overridePendingTransition](http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int, int)). When you leave your activity, call the same method.

Similarly you can use ActivityOptionsCompat to define a custom animation to use during a transition.

ActivityOptionsCompat opts =
    ActivityOptionsCompat.makeCustomAnimation(getActivity(), R.anim.in, R.anim.out);
startActivity(intent, opts.toBundle());
like image 45
Dave Jensen Avatar answered Oct 09 '22 03:10

Dave Jensen