Animation Drawable

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView imageView = findViewById(R.id.imageViewLayout);
AnimationDrawable animationDrawable = new AnimationDrawable();
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v1),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v2),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v3),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v4),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v5),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v6),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v7),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v8),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v9),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v10),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v11),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v12),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v13),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v14),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v15),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v16),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v17),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v18),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v19),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v20),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v21),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v22),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v23),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v24),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v25),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v26),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v27),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v28),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v29),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v30),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v31),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v32),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v33),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v34),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v35),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v36),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v37),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v38),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v39),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v40),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v41),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v42),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v43),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v44),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v45),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v46),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v47),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v48),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v49),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v50),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v51),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v52),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v53),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v54),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v55),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v56),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v57),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v58),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v59),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v60),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v61),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v62),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v63),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v64),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v65),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v66),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v67),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v68),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v69),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v70),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v71),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v72),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v73),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v74),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v75),50);
animationDrawable.setOneShot(false); // true for stop after play the image
imageView.setImageDrawable(animationDrawable);
animationDrawable.start();


}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/imageViewLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</android.support.constraint.ConstraintLayout>

Deixe um comentário