从扩展APK中的图像创建动画

时间:2014-12-19 05:25:32

标签: android animation apk-expansion-files animationdrawable

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

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

但是我一直在寻找,但在这个问题上找不到任何东西。是否可以让动画列表中的项目成为扩展APK文件(zip文件)中的图像。我已经知道如何从Expansion APK文件中获取图像,但我想知道我是否能以某种方式将其放入动画列表中,无论是以编程方式还是仅以某种方式在XML文件中引用。

所以我的问题是,如果可能的话?并且(如果可能的话)我将如何做到这一点?

1 个答案:

答案 0 :(得分:0)

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

创建 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代码中,在activity_main xml中命名为yourImageView的.create imageview

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();
    }
}
相关问题