您可以在名爲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();
}
}
嘿命名yourImageView!謝謝回答!但是,這已經是我所知道的了。 如果我們把你放在這裏但現在而不是在drawable中的情況,first.png,second.png等現在存儲在一個擴展APK中(一個Zip文件可以說main.1.com.example.app.obb )。 我還可以使它工作嗎?我不介意在某處解壓所需的文件。 – DeviousSiddy 2014-12-19 06:52:51