对于 makeSceneTransitionAnimation 有两个静态函数
public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity,
View sharedElement, String sharedElementName)
和
public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity,
Pair<View, String>... sharedElements)
第一个函数调用在 Kotlin 中正常工作,但是在调用第二个函数时,这两个调用都返回错误
val imageTransition = Pair<View, String>(imageView, imageView.getTransitionName());
val textTransition = Pair<View, String>(textView, textView.getTransitionName());
val transitionList = Array(2, { imageTransition });
transitionList[1] = textTransition;
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, *transitionList);
和
val imageTransition = Pair<View, String>(imageView, imageView.getTransitionName());
val textTransition = Pair<View, String>(textView, textView.getTransitionName());
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, imageTransition, textTransition);
是否有适当的方法可以使其正常工作,或者这是互操作的问题?
编辑 添加更改以确保它使用相同的类
val imageView : View = view.findViewById(android.R.id.icon);
val textView : View = view.findViewById(android.R.id.text1);
imageView.setTransitionName("imageTransition");
textView.setTransitionName("textTransition")
val imageTransition : android.support.v4.util.Pair<android.view.View, java.lang.String> = android.support.v4.util.Pair.create(imageView, imageView.getTransitionName() as java.lang.String);
val textTransition : android.support.v4.util.Pair<android.view.View, java.lang.String> = android.support.v4.util.Pair.create(textView, textView.getTransitionName() as java.lang.String);
val transitionList = Array(2, { imageTransition });
transitionList[1] = textTransition;
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, *transitionList);
当前编译器错误:
Error:(72, 84) The spread operator (*foo) may only be applied in a vararg position
Error:(72, 99) No value passed for parameter sharedElementName
还有一个
val imageView : View = view.findViewById(android.R.id.icon);
val textView : View = view.findViewById(android.R.id.text1);
imageView.setTransitionName("imageTransition");
textView.setTransitionName("textTransition")
val imageTransition : android.support.v4.util.Pair<android.view.View, java.lang.String> = android.support.v4.util.Pair.create(imageView, imageView.getTransitionName() as java.lang.String);
val textTransition : android.support.v4.util.Pair<android.view.View, java.lang.String> = android.support.v4.util.Pair.create(textView, textView.getTransitionName() as java.lang.String);
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, imageTransition, textTransition);
当前编译器错误:
Error:(72, 84) Type mismatch: inferred type is android.support.v4.util.Pair<android.view.View, java.lang.String> but android.view.View! was expected
Error:(72, 101) Type mismatch: inferred type is android.support.v4.util.Pair<android.view.View, java.lang.String> but kotlin.String! was expected