andorid 動畫RotateAnimation的使用...
package com.test;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class DrawActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private ImageView img1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView btn = (ImageView) findViewById(R.id.img1);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Animation anim = null;
anim = new RotateAnimation(0.0f,+360.0f);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(3000);
findViewById(R.id.img1).startAnimation(anim); }
}
說明:建構子有四個:Public Constructors
,我們這次使用的是第二種.
- RotateAnimation(Context context, AttributeSet attrs)
- RotateAnimation(float fromDegrees, float toDegrees)
- RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
- RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
留言
張貼留言