不推荐这样写。


推荐这篇:

http://gundumw100.iteye.com/blog/1059297


又是好久没更新博客了,呵呵,忙着上班,忙着带团!一句话,忙着生活赚钱!好吧,废话不多少,今天要写的是loading效果,先给大家看个效果图




程序在加载的时候下面的进度条不断变化,我这里并没有用android自带的动画,写的是一种方法,方法很简单,就是不断地绘制2张图片,利用5个ImageView不断设置不同背景。利用handler来动态更新。两张图片用ps做出来,见下图:






第二张图片是白色的



下面请看代码




//不断发送消息,切换图片
private void playAnimation()
	{
		new Thread(){
			@Override
			public void run()
			{
				while(true)
				{
					for(int i=5;i>0;i--)
					{
						handler.sendEmptyMessage(i);
						try {
							this.sleep(300);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

				}

			}

		}.start();
	}
//handler接受消息进行变化
handler=new Handler(){

			@Override
			public void handleMessage(Message msg) {
				 c.getResources();
				switch(msg.what)
				{
				case 1:
					imgview_1.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_blue));
					imgview_2.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_3.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_4.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_5.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					break;
				case 2:
					imgview_1.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_2.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_blue));
					imgview_3.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_4.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_5.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					break;
				case 3:
					imgview_1.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_2.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_3.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_blue));
					imgview_4.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_5.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					break;
				case 4:
					imgview_1.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_2.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_3.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_4.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_blue));
					imgview_5.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					break;
				case 5:
					imgview_1.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_2.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_3.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_4.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_white));
					imgview_5.setImageDrawable(c.getResources().getDrawable(R.drawable.loading_blue));
					break;
				}
			}
		};



当然,也可以把图片换成其他形状的比如说圆形,大家可以发挥自己的想象力。



这边是我弄的图片:


好啦,这就是大体上的代码,布局文件很简单,就不贴上啦,有问题的朋友可以联系我leepood@gmail.com,祝大家安好!


http://www.leepood.org/#/new-to-android/listview_page/

android监控程序的开启与关闭


http://www.leepood.org/#/new-to-android/android-monitor-apps/