代码之家  ›  专栏  ›  技术社区  ›  Ali

MakeScenetTransitionAnimation在使用AndroidX时显示错误

  •  1
  • Ali  · 技术社区  · 7 年前

    我有以下方法,当我使用 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 回复  |  直到 7 年前
        1
  •  1
  •   MatPag    5 年前

    //Watchout about this import, it is important!!
    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")
    )
    // ... startActivity code here
    

    使用这两个依赖项:

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.1'
    
    推荐文章