Android在配置更改时加载动画

时间:2018-02-14 18:23:09

标签: android kotlin android-animation android-orientation

方向更改发生时,我想播放动画。它是webview的加载器/占位符。 但是当屏幕旋转时,加载器会显示,但没有动画正在播放。 我做错了什么?

override fun onConfigurationChanged(newConfig: Configuration?) {
    when (newConfig?.orientation) {
        Configuration.ORIENTATION_LANDSCAPE -> {
            loader_logo?.visibility = View.VISIBLE
            pulseAnimation(loader_logo)
        }
        Configuration.ORIENTATION_PORTRAIT -> {
            loader_logo?.visibility = View.VISIBLE
            pulseAnimation(loader_logo)
        }
    }
    super.onConfigurationChanged(newConfig)
}

这是动画功能:

private fun pulseAnimation(view: View?) {
    val pulse = AnimationUtils.loadAnimation(this, R.anim.pulse)
    view?.startAnimation(pulse)
}

以下是我的WebView设置:

private fun initWebView() {
    val webSettings = webview.settings
    webSettings.javaScriptEnabled = true
    webview.webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            refresher.isRefreshing = false
            loader_logo.visibility = View.GONE
            if (loader_logo.visibility == View.GONE) loader_logo.clearAnimation()
        }
        override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
            val locale = Locale.getDefault().toString()
            if (locale == "de_DE") webview.loadUrl("file:///android_asset/error_de.html")
            else webview.loadUrl("file:///android_asset/error_en.html")
            isError = true
        }
    }
    webview.loadUrl(url)
}

0 个答案:

没有答案