Android Studio實(shí)現(xiàn)幀動(dòng)畫(huà)
本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)幀動(dòng)畫(huà)的具體代碼,供大家參考,具體內(nèi)容如下
按一定的順序播放靜態(tài)的圖片
1、幾張聯(lián)系的圖片

2、一個(gè)圖片資源管理布局文件:cartoon_source.xml
3、一個(gè)主要的布局文件:cartoon.xml
4、main.java文件
cartoon_source.xml
<?xml version="1.0" encoding="utf-8"?>
//幀動(dòng)畫(huà)資源列表控件
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
//第一個(gè)是圖片資源的地址;第二參數(shù)是這個(gè)圖片播放的事件: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)建一個(gè)數(shù)組,內(nèi)部元素為Bean類(lèi)型;
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();
//設(shè)置點(diǎn)擊監(jiān)聽(tīng)
relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (flag){
anim.start();
flag = false;
}
else{
anim.stop();
flag = true;
}
}
});
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android?廣播接收器BroadcastReceiver詳解
Android開(kāi)發(fā)的四大組件分別是:活動(dòng)(activity),用于表現(xiàn)功能;服務(wù)(service),后臺(tái)運(yùn)行服務(wù),不提供界面呈現(xiàn);廣播接受者(Broadcast Receive),勇于接收廣播;內(nèi)容提供者(Content Provider),支持多個(gè)應(yīng)用中存儲(chǔ)和讀取數(shù)據(jù),相當(dāng)于數(shù)據(jù)庫(kù),本篇著重介紹廣播組件2022-07-07
使用Android studio查看Kotlin的字節(jié)碼教程
這篇文章主要介紹了使用Android studio查看Kotlin的字節(jié)碼教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03
Android獲取應(yīng)用程序大小和緩存的實(shí)例代碼
這篇文章主要介紹了Android獲取應(yīng)用程序大小和緩存的實(shí)例代碼的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
Android利用ConstraintLayout實(shí)現(xiàn)漂亮的動(dòng)畫(huà)詳解
最近在無(wú)意中看到一篇關(guān)于ConstraintLayout的文章,ConstraintLayout是Android Studio 2.2中主要的新增功能之一,下面這篇文章主要給大家介紹了關(guān)于Android利用ConstraintLayout實(shí)現(xiàn)漂亮的動(dòng)畫(huà)的相關(guān)資料,需要的朋友可以參考下。2017-05-05
解析Android開(kāi)發(fā)優(yōu)化之:對(duì)界面UI的優(yōu)化詳解(二)
在一個(gè)應(yīng)用程序中,一般都會(huì)存在多個(gè)Activity,每個(gè)Activity對(duì)應(yīng)著一個(gè)UI布局文件。一般來(lái)說(shuō),為了保持不同窗口之間的風(fēng)格統(tǒng)一,在這些UI布局文件中,幾乎肯定會(huì)用到很多相同的布局2013-05-05
Android通過(guò)HTTP協(xié)議實(shí)現(xiàn)斷點(diǎn)續(xù)傳下載實(shí)例
本篇文章主要介紹了Android通過(guò)HTTP協(xié)議實(shí)現(xiàn)斷點(diǎn)續(xù)傳下載實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-04-04
Android retrofit上傳文件實(shí)例(包含頭像)
下面小編就為大家分享一篇Android retrofit上傳文件實(shí)例(包含頭像),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
Android持久化技術(shù)之SharedPreferences存儲(chǔ)實(shí)例詳解
這篇文章主要介紹了Android持久化技術(shù)之SharedPreferences存儲(chǔ),結(jié)合實(shí)例形式較為詳細(xì)的分析了SharedPreferences存儲(chǔ)的原理、應(yīng)用及具體實(shí)現(xiàn)方法,需要的朋友可以參考下2016-01-01
Android開(kāi)發(fā)之圖片壓縮實(shí)現(xiàn)方法分析
這篇文章主要介紹了Android開(kāi)發(fā)之圖片壓縮實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android圖片壓縮的原理、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-03-03
Android可篩選的彈窗控件CustomFiltControl
這篇文章主要為大家詳細(xì)介紹了Android可篩選的彈窗控件CustomFiltControl,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07

