Android常用动画Frame-By-Frame Animations的使用
在Android的动画中有一种叫做Frame by Frame 的动画效果,就是跟Flash播放一样,是一帧一帧地显示,如果动画是连续并且有规律的话,就跟播放视频一样。
首先在drawable目录下添加anim_nv.xml文件,添加需要显示的图片和间隔时间
package com.example.animation;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;import com.example.widgetdemo.R;public class AnimationXmlDemo3 extends Activity {private Button alpha = null;private ImageView image = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.animation_xml3);alpha = (Button) findViewById(R.id.alpha);image = (ImageView) findViewById(R.id.image);alpha.setOnClickListener(new alphaListener());}class alphaListener implements OnClickListener {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stub//为图片添加图片背景image.setBackgroundResource(R.drawable.anim_nv); AnimationDrawable animationDrawable = (AnimationDrawable) image.getBackground();animationDrawable.start();}}}这样一个连续显示图片的效果就完成了。
源码下载:
点击打开链接