Reputation: 7571
Trying to do a simple shared element animation, and it works fine when just one element is shared. I am trying to experiment by sharing two elements, and that's the problem:
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Main2Activity.this, Pair.create((View) back, "agreedName1"), Pair.create((View) animate, "agreedName2"));
AND
Pair<View, String> h = Pair.create((View) back, "agreedName1");
Pair<View, String> k = Pair.create((View) animate, "agreedName1");
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Main2Activity.this, h, k);
Both don't work, because apparently:
Error:(35, 54) error: no suitable method found for makeSceneTransitionAnimation(Main2Activity,android.support.v4.util.Pair,android.support.v4.util.Pair) method ActivityOptions.makeSceneTransitionAnimation(Activity,View,String) is not applicable (argument mismatch; android.support.v4.util.Pair cannot be converted to View) method ActivityOptions.makeSceneTransitionAnimation(Activity,android.util.Pair...) is not applicable (varargs mismatch; android.support.v4.util.Pair cannot be converted to android.util.Pair)
Even though back
and animate
are both buttons (I even tried typecasting them to views).
Again, this works fine with just one view animation like so:
ActivityOptionsCompat options1 = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, animate, "transition1"); //CANT HAVE TWO TRANSITIONS WITHOUT PAIR HOWEVER
startActivity(intent, options.toBundle());
The way I am doing it (in my first two examples) is how it is said to be done in the developer docs on shared element transition.
The docs clearly state:
To make a scene transition animation between two activities that have more than one shared element, define the shared elements in both layouts with the android:transitionName attribute (or use the View.setTransitionName() method in both activities), and create an ActivityOptions object as follows:
> ActivityOptions options =
> ActivityOptions.makeSceneTransitionAnimation(this,
> Pair.create(view1, "agreedName1"),
> Pair.create(view2, "agreedName2"));
Which I am doing. If I am doing everything right, how come I am getting this error?
Upvotes: 2
Views: 1798
Reputation: 1
It's so easy; You just need a cast of that. Like below example:
ActivityOptions opt = ActivityOptions.makeSceneTransitionAnimation(
this,
(Pair<View, String>) Pair.create(view1, "agreedName1"),
(Pair<View, String>) Pair.create(view2, "agreedName2"));
I hope this can help to you. :)
Upvotes: 0
Reputation: 39836
replace at the top of your class:
import android.support.v4.util.Pair
by
import android.util.Pair
and it should work. You're just using the wrong pair.
Upvotes: 1