开发者

Android animation with multiple jpeg files?

I want to build an animation with some jpegs. I need t开发者_JAVA技巧o change the source of a imageview 24 times per second? What is the easiest way of implementing this? (Newbie)


you can use AnimationDrawable. Use this in your code

private AnimationDrawable anim;
private void Animation() {
        ImageView img = (ImageView)findViewById(R.id.simple_anim);
        anim = (AnimationDrawable)img.getDrawable();
        img.post(run);
    }

    Runnable run = new Runnable() {
        @Override
        public void run() {
            anim.start();
        }
    };

and this in your anim folder create firstlevelanimation.xml something like this

<animation-list android:id="@+id/animation" android:oneshot="false" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/cloud" android:duration="25" />
    <item android:drawable="@drawable/frame1" android:duration="25" />
    <item android:drawable="@drawable/frame2" android:duration="25" />
 </animation-list> 

in your Layout

<ImageView android:id="@+id/simple_anim"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_centerHorizontal="true"
    android:src="@anim/firstlevelanimation"
    />


Use AnimationDrawable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜