Android Studio實(shí)現(xiàn)幀動(dòng)畫
本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)幀動(dòng)畫的具體代碼,供大家參考,具體內(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)畫資源列表控件
<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類型;
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)聽
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實(shí)現(xiàn)系統(tǒng)狀態(tài)欄的隱藏和顯示功能
這篇文章主要介紹了Android實(shí)現(xiàn)系統(tǒng)狀態(tài)欄的隱藏和顯示功能,文中還給大家?guī)?lái)四種方法,大家可以根據(jù)自己需要參考下2018-07-07
Android自定義實(shí)現(xiàn)轉(zhuǎn)盤菜單
旋轉(zhuǎn)菜單是一種占用空間較大,實(shí)用性稍弱的UI,本文主要為大家詳細(xì)介紹了Android如何自定義實(shí)現(xiàn)轉(zhuǎn)盤菜單,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考下2023-12-12
Flutter開發(fā)之支持放大鏡的輸入框功能實(shí)現(xiàn)
在Flutter開發(fā)時(shí),有時(shí)為了優(yōu)化用戶輸入體驗(yàn),往往會(huì)需要輸入框支持在移動(dòng)光標(biāo)過(guò)程中可以出現(xiàn)放大鏡功能。本文將為大家介紹實(shí)現(xiàn)的方法,需要的可以參考一下2022-02-02
Android DataBinding單向數(shù)據(jù)綁定深入探究
看了谷歌官方文章確實(shí)寫的太簡(jiǎn)略了,甚至看完之后有很多地方還不知道怎么回事兒或者怎么用,那么接下來(lái)我將通過(guò)文章全面介紹一下DataBinding單向數(shù)據(jù)綁定2022-11-11

