makeSceneTransitionAnimation在使用AndroidX时显示错误

问题描述 投票:1回答:1

当我使用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

android kotlin androidx
1个回答
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")
)

使用这2个依赖项:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
© www.soinside.com 2019 - 2024. All rights reserved.