1

所以我想创建一些动画 ImageViews,如下所述:

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

但是,我一直在搜索,但找不到有关此主题的任何内容。动画列表中的项目是否可以是扩展 APK 文件(zip 文件)中的图像。我已经知道如何从扩展 APK 文件中获取图像,但我想知道是否可以以某种方式将其放入动画列表中,或者以编程方式,或者只是在 XML 文件中以某种方式引用。

所以我的问题是这是否可能?以及(如果可能的话)我将如何去做这件事?

4

1 回答 1

0

您可以使用放在名为first.png,second.png等的drawable文件夹中的不同图像帧来制作动画效果,并在一定时间间隔后加载它。

创建animation_list.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/first" android:duration="210" />
    <item android:drawable="@drawable/second" android:duration="210" />
    <item android:drawable="@drawable/third" android:duration="210" />
    <item android:drawable="@drawable/fourth" android:duration="210" />
    <item android:drawable="@drawable/fifth" android:duration="210" />
    <item android:drawable="@drawable/sixth" android:duration="210" />

</animation-list>

然后在 MainActivity 代码中 is.create imageview 在activity_main xml中命名为yourImageView

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;

public class MainActivity extends Activity {

    private AnimationDrawable frameAnimation;
    private ImageView view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // Type casting the Image View
        view = (ImageView) findViewById(R.id.yourImageView);

        // Setting animation_list.xml as the background of the image view
        view.setBackgroundResource(R.drawable.animation_list);

        // Type casting the Animation drawable
        frameAnimation = (AnimationDrawable) view.getBackground();
        frameAnimation.start();
    }
}
于 2014-12-19T06:00:49.987 回答