这是我用于活动过渡动画的Kotlin代码
val p1 = Pair.create(imageViewhospitals, "hospitals")
val p2 = Pair.create(textViewhospitals, "title")
val options = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptions.makeSceneTransitionAnimation(this, p1, p2)
} else {
TODO("VERSION.SDK_INT < LOLLIPOP")
}
startActivity(Intent(this,SplashActivity::class.java),options.toBundle())
我收到错误/警告
使用提供的参数不能调用以下任何函数
在ActivityOptions.makeSceneTransitionAnimation
最后我通过改变来解决这个问题
val p1 = Pair.create(imageViewhospitals, "hospitals")
val p2 = Pair.create(textViewhospitals, "title")
至
val p1 = Pair.create<View, String>(imageViewhospitals, "hospitals")
val p2 = Pair.create<View, String>(textViewhospitals, "title")
val imgAnim = Pair.create<View?, String?>(galleryImg, "targetImage")
val textAnim = Pair.create<View?, String?>(textTitle, "targettext")
val options = ActivityOptionsCompat.makeSceneTransitionAnimation( activity, imgAnim, textAnim)
这适用于我使用ActivityOptionsCompat而不是使用ActivityOptions
导入此:
import android.util.Pair as UtilPair
然后呢
val pair1 = UtilPair.create<View,String>(yourView,"myTransition")
val pair2 = UtilPair.create<View,String>(view.package_name,"actNameTransition")
val options = ActivityOptions.makeSceneTransitionAnimation(this,
pair1,
pair2)
导入这个
import androidx.core.util.Pair