Android多线程之控制animation走走停停
首先,定义一个rotate的animation:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000" />
</set>
在code里面,实例化一个freshThrad去画animation。点击stop的时候,call freshThrad.interrupt();将此时wait的freshThrad唤醒,跳用imagview的clearAnimation方法,停止动画。
Java代码
package com.animation.test;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
public class AnimationTest extends Activity implements OnClickListener{
private ImageView icon;
private Animation animation;
private Button btStop;
private Button btStart;
private boolean runFlag = true;
private MyThread freshThrad;
private final static int START_ANIMATION = 100;
private final static int STOP_ANIMATION = 101;
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what){
相关新闻>>
- 发表评论
-
- 最新评论 更多>>