动画总结:不管什么动画、透明还是大小、位置、四个动画可以改变的特效很多!但是其中有一个特效是不叫棘手的就是移动特效!假如我现在要做一个仿HTC圆环解锁的特效动画废话少说上代码解释!
public class ScreenUnLockActivity extends Activity implements OnClickListener{
public Button btn;
public ImageView imageview;
public AnimationSet animation = new AnimationSet(true);//动画集合
public Animation alpha,scale,translate;//透明,尺寸
float mCircleLockTouchX=0 ;//= event.getX() - mLayoutCircle.getLeft();
float mCircleLockTouchY=0 ;//= event.getY() - mLayoutCircle.getTop();
//** Called when the activity is first created. *//*
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// init();
//btn.setOnClickListener(this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_UP){
mCircleLockTouchX = event.getX();
mCircleLockTouchY = event.getY();
Log.i("HHJ", "mCircleLockTouchY: "+mCircleLockTouchY+" mCircleLockTouchY:"+mCircleLockTouchY);
init();
startAnimation();
}
return super.onTouchEvent(event);
}
public void init(){
btn = (Button) findViewById(R.id.btn);
imageview = (ImageView) findViewById(R.id.imageview);
alpha = new AlphaAnimation(1.0f, 0.0f);
alpha.setDuration(1000);
scale = new ScaleAnimation(1f, 3f, 1f, 3f,
Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);
scale.setDuration(1000);
//下面这代码是拿到当前屏幕的中心位置!我屏幕为480*854
translate = new TranslateAnimation(0, getWindowManager().getDefaultDisplay().getWidth()/2-imageview.getHeight()/2,
0, getWindowManager().getDefaultDisplay().getHeight()/2-imageview.getWidth()/2);
translate = new TranslateAnimation(mCircleLockTouchX-imageview.getWidth() / 2- imageview.getLeft(), 240-imageview.getWidth() / 2- imageview.getLeft(),
mCircleLockTouchY- imageview.getHeight() / 2- imageview.getTop(), 425- imageview.getHeight() / 2- imageview.getTop());
//translate.setFillAfter(false);
Log.i("HHJ", "width"+getWindowManager().getDefaultDisplay().getWidth()/2+" height:"+getWindowManager().getDefaultDisplay().getHeight()/2);
translate.setDuration(500);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.btn){
startAnimation();
}
}
public void startAnimation(){
//添加动画集合
animation.addAnimation(alpha);
animation.addAnimation(scale);
animation.addAnimation(translate);
imageview.startAnimation(animation);
}
}