Android(安卓)Frame Animation
16lz
2022-01-23
在xml中定义<animation-list.../> 轮换定义在其中图片资源
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" > <!-- oneshot = true 表示只执行一次,item依次执行 false 表示循环执行, --> <item android:drawable="@drawable/a11" android:duration="1200"/> <!-- duration 图片显示的持续时间 --> <item android:drawable="@drawable/a2" android:duration="1200"/> <item android:drawable="@drawable/a3" android:duration="1200"/></animation-list>
package com.stone.ui;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.widget.Button;import android.widget.ImageView;import com.stone.R;public class AnimationActivity extends Activity {ImageView imageview;AnimationDrawable drawable1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.animation_main);imageview = (ImageView) findViewById(R.id.imageview);drawable1 = (AnimationDrawable) getResources().getDrawable(R.drawable.drawable1);imageview.setBackgroundDrawable(drawable1);}public boolean onTouchEvent(MotionEvent event) {if (event.getAction() == MotionEvent.ACTION_DOWN) {drawable1.start();return true;}return super.onTouchEvent(event);}@Override //window焦点改变 使动画自动开始public void onWindowFocusChanged(boolean hasFocus) {super.onWindowFocusChanged(hasFocus);if (hasFocus) {//start不能直接用在onCreate中,因为此时,AnimationDrawable还没有完全在window中建立好。drawable1.start();}}}
更多相关文章
- android 多线程下载
- android AlertDialog自定义大小
- Android采用SAX解析XML文档
- Android(安卓)ImageSwitcher
- Android(安卓)Service后台处理结果给Activity
- android 自定义Android菜单背景的代码
- tabhost相关报错
- kotlin 之 Android(安卓)AsyncTask
- Android(安卓)View之对现有控件进行拓展实例