当前位置: 首页>后端>正文

kotlin 学习记录1

  // 1、?声明,说明这个对象可以为null
  private var alphaAnimation: AlphaAnimation= null
   override fun attachLayoutRes(): Int {
      return R.layout.activity_splash
   }
    // 2、简化版  重写了attachLayoutRes方法,返回值是R.layout.activity_splash,所以下面的是简写
   override fun attachLayoutRes(): Int = R.layout.activity_splash
    // 3、alphaAnimation?.run  当alphaAnimation为null的时候,
    alphaAnimation?.run {
            // 4、object是匿名对象关键字
            setAnimationListener(object : Animation.AnimationListener {
                override fun onAnimationRepeat(p0: Animation?) {
                }

                override fun onAnimationEnd(p0: Animation?) {
                    jumpToMain()
                }

                override fun onAnimationStart(p0: Animation?) {
                }
            })
        // 5、MainActivity::class.java  等价于  MainActivity.this
        val intent = Intent(this, MainActivity::class.java)
        val splash:ConstraintLayout =  findViewById(R.id.layout_splash);
        splash.startAnimation(alphaAnimation)
        // 6、等价于
        layout_splash.startAnimation(alphaAnimation)

https://www.xamrdz.com/backend/39y1934543.html

相关文章: