Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActivityOptions.makeSceneTransitionAnimation not working in kotlin with multiple views

This is my Kotlin code for activity transition animation

    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())

I am getting an error/warning like

none of the following function can be called with the arguments supplied

on ActivityOptions.makeSceneTransitionAnimation

like image 370
Kishan Solanki Avatar asked Feb 24 '18 12:02

Kishan Solanki


4 Answers

Finally I have solved this problem by changing from

val p1 = Pair.create(imageViewhospitals, "hospitals")
val p2 = Pair.create(textViewhospitals, "title")

to

val p1 = Pair.create<View, String>(imageViewhospitals, "hospitals")
val p2 = Pair.create<View, String>(textViewhospitals, "title")
like image 119
Kishan Solanki Avatar answered Nov 15 '22 17:11

Kishan Solanki


Import this:

import android.util.Pair as UtilPair

and then do

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)
like image 45
Asim Avatar answered Nov 15 '22 17:11

Asim


val imgAnim = Pair.create<View?, String?>(galleryImg, "targetImage")
val textAnim = Pair.create<View?, String?>(textTitle, "targettext")
val options = ActivityOptionsCompat.makeSceneTransitionAnimation( activity, imgAnim, textAnim)

This works for me using ActivityOptionsCompat instead of using ActivityOptions

like image 4
Peter Fam Avatar answered Nov 15 '22 18:11

Peter Fam


Import this

import androidx.core.util.Pair
like image 3
Muhammad Riyas Avatar answered Nov 15 '22 17:11

Muhammad Riyas