这是一个有点不清楚你有什么和什么样的组合还没有尝试过,所以这里是工作的例子:
Animation shrink, grow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//I chose onCreate(), but make the animations however suits you.
//The animations need only be created once.
//From 100% to 70% about center
shrink = new ScaleAnimation(1.0f, 0.7f, 1.0f, 0.7f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF,0.5f);
shrink.setDuration(200);
shrink.setFillAfter(true);
//From 70% to 100% about center
grow = new ScaleAnimation(0.7f, 1.0f, 0.7f, 1.0f, ScaleAnimation.RELATIVE_TO_SELF,0.5f,ScaleAnimation.RELATIVE_TO_SELF,0.5f);
grow.setDuration(200);
grow.setFillAfter(true);
}
@Override
public void onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.startAnimation(shrink);
break;
case MotionEvent.ACTION_UP:
v.startAnimation(grow);
break;
default:
break;
}
}
的动画应该被定义一次,并重新使用,用自己setFillAfter(true)
参数组;这使得绘图棒处于最终位置。当您将动画应用到视图使用startAnimation()
时,setAnimation()
专为管理其自己的开始时间的动画而设计。
希望有助于!
工程就像一个魅力,除了我需要返回true onTouch,否则动画将不会恢复正常。谢谢 – Tom 2011-06-04 22:11:54