Android Studio實現幀動畫
本文實例為大家分享了Android Studio實現幀動畫的具體代碼,供大家參考,具體內容如下
按一定的順序播放靜態(tài)的圖片
1、幾張聯系的圖片
2、一個圖片資源管理布局文件:cartoon_source.xml
3、一個主要的布局文件:cartoon.xml
4、main.java文件
cartoon_source.xml
<?xml version="1.0" encoding="utf-8"?> //幀動畫資源列表控件 <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> //第一個是圖片資源的地址;第二參數是這個圖片播放的事件:120ms; <item android:drawable="@drawable/boy_0" android:duration="120"/> <item android:drawable="@drawable/boy_1" android:duration="120"/> <item android:drawable="@drawable/boy_2" android:duration="120"/> <item android:drawable="@drawable/boy_3" android:duration="120"/> <item android:drawable="@drawable/boy_4" android:duration="120"/> <item android:drawable="@drawable/boy_5" android:duration="120"/> <item android:drawable="@drawable/boy_6" android:duration="120"/> <item android:drawable="@drawable/boy_7" android:duration="120"/> </animation-list>
cartoon.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/boy" android:background="@drawable/cartoon"(背景為資源整合布局文件) android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"/>
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<i> extends AppCompatActivity { /* private static final String TAG = "leo"; private NotificationManager manager; private Notification notification; private PopupWindow popupWindow; //創(chuàng)建一個數組,內部元素為Bean類型; private List<Bean> data = new ArrayList<>(); */ private boolean flag = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cartoon_boy); //獲得布局 RelativeLayout relativeLayout = findViewById(R.id.boy); //從布局中獲得背景 AnimationDrawable anim = (AnimationDrawable)relativeLayout.getBackground(); //設置點擊監(jiān)聽 relativeLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (flag){ anim.start(); flag = false; } else{ anim.stop(); flag = true; } } }); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Android?廣播接收器BroadcastReceiver詳解
Android開發(fā)的四大組件分別是:活動(activity),用于表現功能;服務(service),后臺運行服務,不提供界面呈現;廣播接受者(Broadcast Receive),勇于接收廣播;內容提供者(Content Provider),支持多個應用中存儲和讀取數據,相當于數據庫,本篇著重介紹廣播組件2022-07-07使用Android studio查看Kotlin的字節(jié)碼教程
這篇文章主要介紹了使用Android studio查看Kotlin的字節(jié)碼教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android利用ConstraintLayout實現漂亮的動畫詳解
最近在無意中看到一篇關于ConstraintLayout的文章,ConstraintLayout是Android Studio 2.2中主要的新增功能之一,下面這篇文章主要給大家介紹了關于Android利用ConstraintLayout實現漂亮的動畫的相關資料,需要的朋友可以參考下。2017-05-05解析Android開發(fā)優(yōu)化之:對界面UI的優(yōu)化詳解(二)
在一個應用程序中,一般都會存在多個Activity,每個Activity對應著一個UI布局文件。一般來說,為了保持不同窗口之間的風格統一,在這些UI布局文件中,幾乎肯定會用到很多相同的布局2013-05-05Android持久化技術之SharedPreferences存儲實例詳解
這篇文章主要介紹了Android持久化技術之SharedPreferences存儲,結合實例形式較為詳細的分析了SharedPreferences存儲的原理、應用及具體實現方法,需要的朋友可以參考下2016-01-01Android可篩選的彈窗控件CustomFiltControl
這篇文章主要為大家詳細介紹了Android可篩選的彈窗控件CustomFiltControl,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07