使用AndroidX时,makeSceneTransitionAnimation显示错误

时间:2019-01-29 16:52:04

标签: android kotlin androidx

我有以下方法,当我使用android.support.v4

override fun onClick(movie: Movie, poster: ImageView, name: TextView) {
            val intent = Intent(activity, DetailActivity::class.java).apply {
                putExtras(Bundle().apply {
                    putParcelable(EXTRA_MOVIE, movie)
                })
            }
            val activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
                    requireActivity(),

                    // Now we provide a list of Pair items which contain the view we can transitioning
                    // from, and the name of the view it is transitioning to, in the launched activity
                    Pair<View, String?>(poster, ViewCompat.getTransitionName(poster)),
                    Pair<View, String?>(name, ViewCompat.getTransitionName(name)))

            // Now we can start the Activity, providing the activity options as a bundle
            ActivityCompat.startActivity(requireContext(), intent, activityOptions.toBundle())
        }

现在我想迁移到androidx.core.app。由于某种原因,它在makeSceneTransitionAnimation上显示错误,提示non of the following functions can be called with the arguments supplied

有人遇到这样的问题吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

对我来说,它是这样工作的:

import androidx.core.util.Pair

//onCreate code avoided here
val testView = ImageView(this)

val activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
     MainActivity.this,
     Pair<View, String>(testView, "hi1"),
     Pair<View, String>(testView, "hi2")
)

使用这两个依赖项:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'