1

所以我想创造一些动画ImageViews中描述:扩张APK创建一个从图像动画

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

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

所以我的问题是如果这是可能的?并且(如果可能的话)我会如何去做这件事?

回答

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代码is.create的ImageView在activity_main XML

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

嘿命名yourImageView!谢谢回答!但是,这已经是我所知道的了。 如果我们把你放在这里但现在而不是在drawable中的情况,first.png,second.png等现在存储在一个扩展APK中(一个Zip文件可以说main.1.com.example.app.obb )。 我还可以使它工作吗?我不介意在某处解压所需的文件。 – DeviousSiddy 2014-12-19 06:52:51