Loading Image
Android doesn’t handle animated gifs, but here’s one way to display an animated loading image that is similar to the Spinner style of ProgressDialog.
Image Files:
drawable/loading.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/loading_1" android:duration="100" />
<item android:drawable="@drawable/loading_2" android:duration="100" />
<item android:drawable="@drawable/loading_3" android:duration="100" />
<item android:drawable="@drawable/loading_4" android:duration="100" />
<item android:drawable="@drawable/loading_5" android:duration="100" />
<item android:drawable="@drawable/loading_6" android:duration="100" />
<item android:drawable="@drawable/loading_7" android:duration="100" />
<item android:drawable="@drawable/loading_8" android:duration="100" />
<item android:drawable="@drawable/loading_9" android:duration="100" />
<item android:drawable="@drawable/loading_10" android:duration="100" />
<item android:drawable="@drawable/loading_11" android:duration="100" />
<item android:drawable="@drawable/loading_12" android:duration="100" />
</animation-list>
MyActivity.java
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MyActivity extends Activity {
ImageView loading;
AnimationDrawable loadAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout main = new LinearLayout(this);
main.setOrientation(LinearLayout.VERTICAL);
setContentView(main);
loading = new ImageView(this);
loading.setImageResource(R.drawable.loading);
loadAnimation = (AnimationDrawable)loading.getDrawable();
main.addView(loading);
}
//can't start animating in OnCreate, so start when window becomes in focus
@Override
public void onWindowFocusChanged(boolean hasFocus){
loadAnimation.start();
}
}
邮箱:steven9801@163.com
QQ: 48039387