Step by step tutorial how to create Animations: zoom, clockwise, fade, slide, move, blink on Android Studio 4.1.3. Follow video tutorial: Create new project with Application name: My animations. In app->res-> create New Directory: anim. In app->res-> drawable drag and drop a picture: pic.png In app->java->MainActivity.java write the code:
package com.example.toyo.myanimations

import android.app.Activity
import android.os.Bundle
import android.view.View
import android.view.animation.AnimationUtils
import android.widget.ImageView

class MainActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
    fun clockwise(view: View?) {
        val image = findViewById<View>(R.id.imageView) as ImageView
        val animation = AnimationUtils.loadAnimation(applicationContext,
                R.anim.zoom)
        image.startAnimation(animation)
    }
    fun zoom(view: View?) {
        val image = findViewById<View>(R.id.imageView) as ImageView
        val animation1 = AnimationUtils.loadAnimation(applicationContext,
                R.anim.clockwise)
        image.startAnimation(animation1)
    }
    fun fade(view: View?) {
        val image = findViewById<View>(R.id.imageView) as ImageView
        val animation1 = AnimationUtils.loadAnimation(applicationContext,
                R.anim.fade)
        image.startAnimation(animation1)
    }
    fun slide(view: View?) {
        val image = findViewById<View>(R.id.imageView) as ImageView
        val animation1 = AnimationUtils.loadAnimation(applicationContext, R.anim.slide)
        image.startAnimation(animation1)
    }
    fun move(view: View?) {
        val image = findViewById<View>(R.id.imageView) as ImageView
        val animation1 = AnimationUtils.loadAnimation(applicationContext, R.anim.move)
        image.startAnimation(animation1)
    }
    fun blink(view: View?) {
        val image = findViewById<View>(R.id.imageView) as ImageView
        val animation1 = AnimationUtils.loadAnimation(applicationContext,
                R.anim.blink)
        image.startAnimation(animation1)
    }
}
  In app->res->layout->activity_main.xml write the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="449dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginEnd="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="40dp"
        android:src="@drawable/pic" />
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_marginStart="54dp"
        android:layout_marginLeft="54dp"
        android:layout_marginTop="70dp"
        android:onClick="clockwise"
        android:text="zoom" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="clockwise"
        android:id="@+id/button2"
        android:layout_alignTop="@+id/button"
        android:layout_centerHorizontal="true"
        android:onClick="zoom"/>
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/button2"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="1dp"
        android:layout_marginEnd="53dp"
        android:layout_marginRight="53dp"
        android:onClick="fade"
        android:text="fade" />
    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button3"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_marginStart="252dp"
        android:layout_marginLeft="252dp"
        android:layout_marginTop="2dp"
        android:onClick="blink"
        android:text="blink" />
    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button"
        android:layout_marginLeft="55dp"
        android:layout_marginTop="1dp"
        android:onClick="slide"
        android:text="slide" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="move"
        android:onClick="move"
        android:id="@+id/button5"
        android:layout_below="@+id/button2"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignStart="@+id/button2" />

</RelativeLayout>
  In app->res->anim-> create zoom.xml file and write the code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXScale="0.5"
        android:toXScale="3.0"
        android:fromYScale="0.5"
        android:toYScale="3.0"
        android:duration="1000"
        android:pivotX="25%"
        android:pivotY="25%" >
    </scale>

    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:startOffset="1000"
        android:fromXScale="3.0"
        android:toXScale="0.5"
        android:fromYScale="3.0"
        android:toYScale="0.5"
        android:duration="1000"
        android:pivotX="25%"
        android:pivotY="25%" >
    </scale>

</set>
  In app->res->anim-> create clockwise.xml file and write the code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="5000" >
    </rotate>

    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:startOffset="5000"
        android:fromDegrees="360"
        android:toDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="5000" >
    </rotate>

</set>
  In app->res->anim-> create fade.xml file and write the code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >

    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:duration="2000" >
    </alpha>

    <alpha
        android:startOffset="2000"
        android:fromAlpha="1"
        android:toAlpha="0"
        android:duration="2000" >
    </alpha>

</set>
  In app->res->anim-> create slide.xml file and write the code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="0.0"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>
  In app->res->anim-> create move.xml file and write the code:
<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

    <translate
        android:fromXDelta="0%p"
        android:toXDelta="50%p"
        android:duration="800" />

    <translate
        android:startOffset="1000"
        android:fromXDelta="50%p"
        android:toXDelta="-50%p"
        android:duration="800" />

</set>
  In app->res->anim-> create blink.xml file and write the code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="600"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh

*