未解决的参考:imageSwitcher

时间:2018-03-25 18:04:08

标签: kotlin imageswitcher

我正在尝试为电池动画创建一个图像切换器。使用kotlin支持有什么我想念的吗?

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.widget.ImageSwitcher
import java.util.*

class SplashScreen : AppCompatActivity() {

    private val splashTimeOut = 6000L
    private val chargeAnimation = arrayOf(
            R.drawable.charge_1,
            R.drawable.charge2,
            R.drawable.charge_3,
            R.drawable.charge_4)
    private var index = 0

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)

        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_FULLSCREEN or
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

        val t = Timer()
        //Set the schedule function and rate
        t.scheduleAtFixedRate(object : TimerTask() {

            override fun run() {
                //Called each time when 1000 milliseconds (1 second) (the period parameter)

                // If index reaches maximum reset it
                if (index + 1 < chargeAnimation.size) index + 1 else 0
                runOnUiThread { ***imageSwitcher***.setImageResource(chargeAnimation[index]) }
            }

        }, 500, 1000)

        Handler().postDelayed(Runnable{
            kotlin.run{
                val intent = Intent(this, RegisterScreen::class.java)
                startActivity(intent)
                finish()
            }
        }, splashTimeOut)}}

0 个答案:

没有答案