Animation(2、帧动画)
android帧动画相对简单,只是将资源中的图片文件依据一定规则播放,类似GIF文件。
首先定义ani.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/aboutdlg_logo" android:duration="500"/> <item android:drawable="@drawable/actionbar_logo" android:duration="500"/> <item android:drawable="@drawable/aboutdlg_logo" android:duration="500"/> <item android:drawable="@drawable/actionbar_logo" android:duration="500"/> </animation-list>
然后进行调用:
public class MainActivity extends Activity { private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView)findViewById(R.id.image); imageView.setBackgroundResource(R.anim.ani); AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground(); animationDrawable.start(); } }