Android Frame Animation

来源:互联网 发布:小米软件自动升级 编辑:程序博客网 时间:2024/05/16 19:05

在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();}}}


0 0