Android中的动画详解系列


Android中的动画详解系列

逐帧动画其实很简单,下面我们来看一个例子:

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <animation-list
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:oneshot="false">
  5. <itemandroid:drawable="@drawable/progress_1"android:duration="200"/>
  6. <itemandroid:drawable="@drawable/progress_2"android:duration="200"/>
  7. <itemandroid:drawable="@drawable/progress_3"android:duration="200"/>
  8. <itemandroid:drawable="@drawable/progress_4"android:duration="200"/>
  9. <itemandroid:drawable="@drawable/progress_5"android:duration="200"/>
  10. <itemandroid:drawable="@drawable/progress_6"android:duration="200"/>
  11. <itemandroid:drawable="@drawable/progress_7"android:duration="200"/>
  12. <itemandroid:drawable="@drawable/progress_8"android:duration="200"/>
  13. </animation-list>

 

android:oneshot="false"的意思是循环播放

界面布局:

  1. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical">
  5. <Button
  6. android:layout_width="wrap_content"
  7. android:layout_height="wrap_content"
  8. android:text="开始"
  9. android:onClick="start"/>
  10. <Button
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:text="停止"
  14. android:onClick="stop"/>
  15. <ImageView
  16. android:id="@+id/iv"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:background="@anim/zhuzhen"
  20. android:layout_gravity="center"/>
  21. </LinearLayout>

MainActivity.java

  1. package com.example.testanimation;
  2. import android.graphics.drawable.AnimationDrawable;
  3. import android.os.Bundle;
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.view.View;
  6. import android.widget.ImageView;
  7. publicclass MainActivity extends ActionBarActivity {
  8. private AnimationDrawable anim;
  9. @Override
  10. protectedvoid onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13. ImageView iv = (ImageView) findViewById(R.id.iv);
  14. anim = (AnimationDrawable) iv.getBackground();
  15. }
  16. publicvoid start(View view){
  17. anim.start();
  18. }
  19. publicvoid stop(View view){
  20. anim.stop();
  21. }
  22. }

运行效果:

更多详情见请继续阅读下一页的精彩内容:

  • 1
  • 2
  • 3
  • 4
  • 下一页
【内容导航】
第1页:逐帧动画 第2页:飞舞的蝴蝶
第3页:自定义动画研究 第4页:Activity之间切换动画

相关内容

    暂无相关文章