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