在drawable目录下新建一个XML文件,内容如下,假定名称image_list.xml:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/page_loading_01" android:duration="100" /> <item android:drawable="@drawable/page_loading_02" android:duration="100" /> <item android:drawable="@drawable/page_loading_03" android:duration="100" /> <item android:drawable="@drawable/page_loading_04" android:duration="100" /> <item android:drawable="@drawable/page_loading_05" android:duration="100" /> <item android:drawable="@drawable/page_loading_06" android:duration="100" /> <item android:drawable="@drawable/page_loading_07" android:duration="100" /> <item android:drawable="@drawable/page_loading_08" android:duration="100" /> <item android:drawable="@drawable/page_loading_09" android:duration="100" /> <item android:drawable="@drawable/page_loading_10" android:duration="100" /> <item android:drawable="@drawable/page_loading_11" android:duration="100" /> <item android:drawable="@drawable/page_loading_12" android:duration="100" /> <item android:drawable="@drawable/page_loading_13" android:duration="100" /> <item android:drawable="@drawable/page_loading_14" android:duration="100" /> </animation-list> //page_loading_xx为Png图片文件,位于drawable目录下; 实现代码:
ImageView animationImage = (ImageView)this.findViewById(R.id.imageView);//初始化image控件,这在控件属性上将src指向image_list.xml; AnimationDrawable AD = (AnimationDrawable)animationImage.getDrawable(); AD.setCallback(animationImage); AD.setVisible(true, false); AD.start();//显示动画 AD.stop();//停止动画
关键字词: