dialog实现自定义动画progress
2012-04-24 12:54 omgee 阅读(885) 评论(0) 编辑 收藏 举报上章写了一个dialog实现自定义静态图的demo,现在来现实播放自定义动画的进度条
一.先导入动画,这边是不可以直接加载gif动态图片的,所以要把它打散,我使用了工具Easy GIF Animator
导入gif 图片
然后右击任何一张图片,有个select all frame , 全选之后,在工具栏上有一个frame--export selected frames 就导出了所有帧图片
二.在工程中res文件夹新建一个drawable文件夹,把图片导入,再建一个animal_pro.xml
animal_pro.xml
<?xml version="1.0" encoding="UTF-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="20" android:drawable="@drawable/car00" /> <item android:duration="20" android:drawable="@drawable/car01" /> <item android:duration="20" android:drawable="@drawable/car02" /> <item android:duration="20" android:drawable="@drawable/car03" /> <item android:duration="20" android:drawable="@drawable/car04" /> <item android:duration="20" android:drawable="@drawable/car05" /> <item android:duration="20" android:drawable="@drawable/car06" /> <item android:duration="20" android:drawable="@drawable/car07" /> <item android:duration="20" android:drawable="@drawable/car08" /> <item android:duration="20" android:drawable="@drawable/car09" /> <item android:duration="20" android:drawable="@drawable/car10" /> <item android:duration="20" android:drawable="@drawable/car11" /> <item android:duration="20" android:drawable="@drawable/car12" /> <item android:duration="20" android:drawable="@drawable/car13" /> <item android:duration="20" android:drawable="@drawable/car14" /> <item android:duration="20" android:drawable="@drawable/car15" /> <item android:duration="20" android:drawable="@drawable/car16" /> <item android:duration="20" android:drawable="@drawable/car17" /> <item android:duration="20" android:drawable="@drawable/car18" /> <item android:duration="20" android:drawable="@drawable/car19" /> <item android:duration="20" android:drawable="@drawable/car20" /> <item android:duration="20" android:drawable="@drawable/car21" /> <item android:duration="20" android:drawable="@drawable/car22" /> <item android:duration="20" android:drawable="@drawable/car23" /> <item android:duration="20" android:drawable="@drawable/car24" /> <item android:duration="20" android:drawable="@drawable/car25" /> <item android:duration="20" android:drawable="@drawable/car26" /> <item android:duration="20" android:drawable="@drawable/car27" /> <item android:duration="20" android:drawable="@drawable/car28" /> <item android:duration="20" android:drawable="@drawable/car29" /> <item android:duration="20" android:drawable="@drawable/car30" /> <item android:duration="20" android:drawable="@drawable/car31" /> <item android:duration="20" android:drawable="@drawable/car32" /> <item android:duration="20" android:drawable="@drawable/car33" /> <item android:duration="20" android:drawable="@drawable/car34" /> </animation-list>
三.建立一个dialog的view..progress.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/progress_img" > <ImageView android:id="@+id/animal_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_mytce" /> </RelativeLayout>
java代码
四.先建一个dialog加载动画视图
//进程图片加载框 public AlertDialog.Builder dialog_progress() { AlertDialog.Builder builder = new Builder(LinkMap.this); View view =super.getLayoutInflater().inflate(R.layout.progress,(ViewGroup) findViewById(R.id.progress_img)); final ImageView iv=(ImageView)view.findViewById(R.id.animal_img); iv.setImageResource(R.drawable.animal_pro);//绑定数据源 //启动 动画,因为如果没有启动方法,它没办法自己启动 iv.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub AnimationDrawable animationDrawable=(AnimationDrawable)iv.getDrawable();//获取imageview绘画 animationDrawable.start();//开始绘画 } }); // new Thread(new Runnable() { // // @Override // public void run() { // // TODO Auto-generated method stub // AnimationDrawable animationDrawable=(AnimationDrawable)iv.getDrawable();//获取imageview绘画 // animationDrawable.start();//开始绘画 // // } // }).start();//同一个mt,但是在Thread中就不可以,如果用同一 builder.setView(view); return builder; }
五.初始时显示进度条
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); //进程加载 dialog_pro=dialog_progress().create(); dialog_pro.show();
}
效果如下:
Crazy Cherry:everything is possible!