Making animation in Android Studio (Java,Xml)


 


Hey today im gonna show you how to make animation in Android Studio

First open empty project 

Secondly delete TextView and change with ImageView.


<ImageView
android:id="@+id/AnimatedImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Then add images in drawble



and create a animation drawble




 root must be animation-list
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="1000"
android:drawable="@drawable/animate1"/>
<item android:duration="1000"
android:drawable="@drawable/animate2"/>
<item android:duration="1000"
android:drawable="@drawable/animate3"/>
<item android:duration="1000"
android:drawable="@drawable/animate4"/>
<item android:duration="1000"
android:drawable="@drawable/animate5"/>
<item android:duration="1000"
android:drawable="@drawable/animate1"/>

</animation-list>
1000 is for 1 second
Last item must be same with first item.

add src for image
<ImageView
android:src="@drawable/animation"
android:id="@+id/AnimatedImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
package com.example.deneme3;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

ImageView img; // desgribing image
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

img = findViewById(R.id.AnimatedImage); //image's id

AnimationDrawable animationDrawable = (AnimationDrawable) img.getDrawable(); // animation
animationDrawable.start(); // starting
}
}

thx

Comments

Popular Posts