360内存清理内存小球动画效果(二)

这个动画效果的实现主要依靠的是ClipDrawable类.下面是ClipDrawable类的简介:

A Drawable that clips another Drawable based on this Drawable's current level value. You can control how much the child Drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars, by increasing the drawable's level with setLevel().

Note: The drawable is clipped completely and not visible when the level is 0 and fully revealed when the level is 10,000.

It can be defined in an XML file with the <clip> element. For more information, see the guide to Drawable Resources.

下面是clip的xml文件

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipOrientation="vertical"
    android:drawable="@drawable/taskmanager_circle_full"
    android:gravity="bottom" >
</clip>


下面是layout的布局文件


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

<ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img_background"
    android:src="@drawable/taskmanager_background"
    />
<ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img_vary"
    android:src="@drawable/vary"
    
    />
</RelativeLayout>


下面是java代码区域

public class MainActivity extends Activity {
	private final static int MAX = 10000;
	private int current = 0;
	private final static int INCREMENT = 100;
	protected static final int START = 1;
	boolean isFinished = true;;
	private ImageView img;
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case START:
				img.setImageResource(R.drawable.vary);
				ClipDrawable clip = (ClipDrawable) img.getDrawable();
				clip.setLevel(current);
				if(current == MAX){
					if(timer != null){
						timer.cancel();
					}
					if(task != null){
						task.cancel();
					}
				}
				isFinished = true;
				
				break;

			default:
				break;
			}
		};
	};
	private Timer timer;
	private TimerTask task;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		img = (ImageView) findViewById(R.id.img_vary);
		getAnima();
	}
	
	private void getAnima(){
		timer = new Timer();
		task = new TimerTask() {
			@Override
			public void run() {
				while(isFinished){
					isFinished = false;
					Message msg = new Message();
					msg.what = START;
					msg.obj = current;
					System.out.println("current = "+current);
					current += 100;
					handler.sendMessage(msg);
				}
			}
		};
		
		timer.schedule(task, 0, 1);
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值