Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize frame Animation with Android Studio

Shulou Source: shulou.com Published: 2022-06-02 15:29:26 09月22日 Update

This article mainly explains "how Android Studio realizes frame animation". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how Android Studio realizes frame animation" together!

Play static pictures in a certain order

1. A few pictures of contact

2. A picture resource management layout file: cartoon_source.xml

3. A main layout file: cartoon.xml

4. Main.java file

cartoon_source.xml

//Frame animation resource list control//The first parameter is the address of the image resource; the second parameter is the event played by this image: 120ms;

cartoon.xml

main.java

package com.example.imageview;import androidx.appcompat.app.AppCompatActivity;import androidx.appcompat.widget.Toolbar;import androidx.core.app.NotificationCompat;import android.annotation.SuppressLint;import android.app.AlertDialog;import android.app.Notification;import android.app.NotificationChannel;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.DialogInterface;import android.content.Intent;import android.graphics.BitmapFactory;import android.graphics.Color;import android.graphics.drawable.AnimationDrawable;import android.graphics.drawable.Drawable;import android.os.Build;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.Button;import android.widget.ListView;import android.widget.PopupWindow;import android.widget.ProgressBar;import android.widget.RelativeLayout;import android.widget.TextView;import java.nio.channels.Channel;import java.util.ArrayList;import java.util.List;public class MainActivity extends AppCompatActivity { /* private static final String TAG = "leo"; private NotificationManager manager; private Notification notification; private PopupWindow popupWindow; //Create an array with Bean elements inside; private List data = new ArrayList(); */ private boolean flag = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cartoon_boy); //Get Layout RelativeLayout relativeLayout = findViewById(R.id.boy); //Get background from layout AnimationDrawable anim = (AnimationDrawable)relativeLayout.getBackground(); //Settings Click to monitor relativeLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (flag){ anim.start(); flag = false; } else{ anim.stop(); flag = true; } } });} Thank you for reading, the above is "Android Studio how to achieve frame animation" content, after learning this article, I believe that everyone on Android Studio how to achieve frame animation this problem has a deeper understanding, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Animation pictures layouts files resources learning content events elements parameters picture resources addresses that is ideas situations controls arrays articles more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple OPPO Reno macOS Huawei