Kotlin: timing animation of Android Homepage

Keywords: Android Java

Here are several steps:

  1. Set the Activity of the home page as the start page
  2. Rewrite onCreate, call two functions, defined animation function, monitor function

First, set the start page: add the intent filter to the activity. The first action is to set the main page, and the second is specifically defined as the start page. Note the theme here. We set the full screen home page, so we need to remove the action bar.

 <activity
            android:name=".brow"
            android:label="My borrowing" />
        <activity android:name=".about" />
        <activity android:name=".history" />
        <activity android:name=".MainActivity"
            android:theme="@style/Theme.Design.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
  </activity>

Next, work on the parts of onCreate.

    var ass = AnimationSet(false)//Animated objects
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var login_img = findViewById<ImageView>(R.id.login_img)//Get home login
        setContentView(R.layout.activity_main)
        startAni()//Start animation
        iniNext()//Switch to other pages after the start of monitoring

    }


    fun startAni() {
        //Define Animation: parameters: start width scale X, end width scale X, start height scale, end height scale, define X anchor, define Y anchor (now the center)
        val sa = ScaleAnimation(
                1f, 1.1f, 1f, 1.1f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f)

        sa.duration = 2000//2s
        sa.fillAfter = true
        ass.addAnimation(sa)
        login_img.startAnimation(ass)//Start animation
    }


    fun iniNext() {
        ass.setAnimationListener(object: Animation.AnimationListener {
        //kotlin implements anonymous class, object: xx{override xxx}

            override fun onAnimationStart(Ani:Animation) {
                //Snackbar.make(mycontext, "welcome", Snackbar.LENGTH_LONG).show()
                Toast.makeText(this@MainActivity,"Welcome to use",Toast.LENGTH_LONG).show()

            }


         override fun onAnimationRepeat(ani:Animation) {

            }

            //After listening to the animation

           override fun onAnimationEnd(ani:Animation){
               var intent=Intent(this@MainActivity,WDMain::class.java)
                startActivity(intent);//Main interface
                finish()
            }
        })
    }

ok.

Posted by Hybride on Tue, 31 Dec 2019 00:00:44 -0800