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

 

posted @ 2013-03-22 11:57  Fredric_2013  阅读(203)  评论(0编辑  收藏  举报