ActivityOptions.makeSceneTransitionAnimation not working in kotlin with multiple views
Asked Answered
A

6

11

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

Ass answered 24/2, 2018 at 12:48 Comment(0)
A
22

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")
Ass answered 24/2, 2018 at 13:54 Comment(2)
what import did you use?Befog
@Befog androidx.core.util.Pair.createAss
E
4

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)
Exaction answered 9/8, 2018 at 13:59 Comment(0)
D
4
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

Dioecious answered 30/10, 2018 at 21:32 Comment(0)
H
3

Import this

import androidx.core.util.Pair
Haggerty answered 20/4, 2019 at 8:56 Comment(0)
S
0

Even though I'm using Kotlin, I had to specify the redundant Pair type for the code to run! so just add these: <View, String>

final:

    val options = ActivityOptions.makeSceneTransitionAnimation(this,
        Pair.create<View, String>(viewHolder.imageView, getString(R.string.shared_animation_imageview)),
        Pair.create<View, String>(viewHolder.tvTitle, getString(R.string.shared_animation_title)))

    startActivity(intent, options.toBundle())
Silage answered 19/3, 2020 at 21:12 Comment(0)
B
0

I was having the same issue and in my case i needed to get the imports corrected. Here's the code that worked for me in addition to the imports.

import androidx.core.util.Pair
import androidx.core.app.ActivityOptionsCompat
import androidx.core.app.ActivityCompat


val intent = Intent(activity, SecondActivity::class.java)
val pair1 = Pair.create<View, String>(view1, "string1")
val pair2 = Pair.create<View, String>(view2, "string2")
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pair1, pair2)
ActivityCompat.startActivity(activity, intent, options.toBundle())
Befog answered 20/9, 2020 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.