android之帧动画实现
来源:互联网 发布:baocms源码下载 编辑:程序博客网 时间:2024/05/17 03:47
今天实现了一个帧动画的例子,
首先在res/anim下建立一个frame.xml来存放帧动画
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/girl_1" android:duration="100"/> <item android:drawable="@drawable/girl_2" android:duration="100"/> <item android:drawable="@drawable/girl_3" android:duration="100"/> <item android:drawable="@drawable/girl_4" android:duration="100"/> <item android:drawable="@drawable/girl_5" android:duration="100"/> <item android:drawable="@drawable/girl_6" android:duration="100"/> <item android:drawable="@drawable/girl_7" android:duration="100"/> <item android:drawable="@drawable/girl_8" android:duration="100"/> <item android:drawable="@drawable/girl_9" android:duration="100"/> <item android:drawable="@drawable/girl_10" android:duration="100"/> <item android:drawable="@drawable/girl_11" android:duration="100"/> </animation-list>
引用的是drawable下面的图片,duration是设置时间是100毫秒
看下main.xml的布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="播放动画" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="停止动画" /> </LinearLayout> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="单次播放" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="循环播放" /> </RadioGroup> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拖动进度条修改透明度(0 - 255)之间" /> <SeekBar android:id="@+id/seekBar1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <ImageView android:id="@+id/imageView1" android:layout_width="200dip" android:layout_height="200dip" android:background="@anim/frame" /></LinearLayout>
下面是控制帧动画的主要代码:
public class FrameDemoActivity extends Activity { /** Called when the activity is first created. */private Button button1,button2;private RadioGroup radioGroup;private RadioButton radioButton1,radioButton2;private SeekBar seekBar;private ImageView imageView1;private AnimationDrawable animationDrawable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1=(Button) this.findViewById(R.id.button1); button2=(Button) this.findViewById(R.id.button2); radioGroup=(RadioGroup) this.findViewById(R.id.radioGroup1); radioButton1=(RadioButton) this.findViewById(R.id.radioButton1); radioButton2=(RadioButton) this.findViewById(R.id.radioButton2); seekBar=(SeekBar) this.findViewById(R.id.seekBar1); imageView1=(ImageView) this.findViewById(R.id.imageView1); //通过ImageView对象拿到背景显示的AnimationDrawable animationDrawable=(AnimationDrawable) imageView1.getBackground(); button1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(!animationDrawable.isRunning()){animationDrawable.start();}}}); button2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(animationDrawable.isRunning()){animationDrawable.stop();}}}); radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif(checkedId==radioButton1.getId()){//设置单次播放animationDrawable.setOneShot(true);}else if(checkedId==radioButton2.getId()){//设置循环播放animationDrawable.setOneShot(false);}//设置播放后重新启动animationDrawable.stop();animationDrawable.start();}}); //监听的进度条修改透明度 seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub//设置动画Alpha值animationDrawable.setAlpha(progress);//通知imageView 刷新屏幕imageView1.postInvalidate();}}); }}
运行效果如图所示:
进度条seekbar是设置透明度的。
- Android动画之帧动画实现方式
- android之帧动画实现
- Android动画之animation-list实现逐帧动画
- Android动画详解之Android 动画属性和实现方法之帧动画(二)
- Android动画之Tween动画实现
- Android动画之---帧动画
- Android 动画之帧动画
- Android动画之帧动画
- Android动画之帧动画
- Android动画之帧动画
- Android动画之帧动画
- Android开发之动画实现
- Android之gif动画实现
- Android 之动画实现animation
- Android动画之帧动画,及实现京东下拉加载动画
- Android动画学习(一)之动画概述和帧动画实现
- Android帧动画实现
- Android实现帧动画
- 在Ubuntu中编译、安装 gcc4.1.1 过程以及遇到的问题
- udp和tcp
- 【转】尚学堂shopping的经验
- android 中wifi的应用
- unidac连接firebird的embed版
- android之帧动画实现
- 在VC6.0和VS2010下编译pthreads-w32-2-8-0-release.exe
- SAP笔试
- 首次正式测试之后
- opencv静态库的创建
- Java设计模式之工厂方法模式
- 判断单链表是否有环及确定环的入口结点问题
- 追求“纯粹的技术”的误区
- 游戏外挂基本原理及实现