3

我想做的事

SplashActivity在&之间进行平滑过渡/动画LoginActivity

(两个活动都使用 androidx.appcompat.app.AppCompatActivity)

项目依赖

implementation 'com.google.android.material:material:1.0.0-alpha3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha3'
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'

SplashActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    with(window) {
        requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)

        exitTransition = Slide(Gravity.BOTTOM)
    }
    //Handler codes waiting for around 700ms...
}

fun startLoginActivity() {
    // Check if we're running on Android 5.0 or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
         startActivity(intent, ActivityOptions
                                   .makeSceneTransitionAnimation(this)
                                   .toBundle())
    } else {
         //Swap without transition
         startActivity(intent)
    }
    finishAfterTransition()
}

登录活动.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    with(window) {
        requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)

        allowEnterTransitionOverlap = true
        enterTransition = Slide(Gravity.TOP)
        exitTransition = Explode()
    }

    setContentView(R.layout.login_activity)
    if (savedInstanceState == null) {
        supportFragmentManager.transaction(now = true) {
            replace(R.id.loginContainer, LoginFragment.newInstance())
        }
    }
}

发生了什么

  1. 调用时SplashActivity.startLoginActivity(),窗口淡出并关闭,然后用 重新打开LoginActivity。这不是我所期望的
  2. 当我关闭 LoginActivity 时,视图组件在LoginFragment后台停留在那里,但没有窗口。这不应该发生。

关于如何解决问题的任何想法?

笔记:

SplashActivity&LoginActivity中,我都无法使用来自androidx.transition.*.

这是因为androidx.AppCompatActivity正在返回 android.view.window,并且我必须使用 Classes from android.transition.*,这是有效的,但我不确定这是否是错误的原因。

4

0 回答 0