+-

当按下一个按钮时,我需要设置该按钮的动画….按钮将在释放后按下和原始尺寸缩小一点..(非常像火药)
我用这个:
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.9"
android:toYScale="0.9" >
</scale>
但它不能根据我的需要工作,,,我需要按钮保持很小,直到它被按下.在发布时变得正常.
最佳答案
你可以创建一个第二个动画来返回unlicked状态,如下所示:
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fillAfter="true"
android:fromXScale="0.9"
android:fromYScale="0.9"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" >
</scale>
然后 :
yourButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// start your first zoom out Animation here
break;
case MotionEvent.ACTION_UP:
// start zoom in animation which returns to original state
break;
}
return false;
}
});
不要忘记将动画中的fillAfter设置为true,否则它将在持续时间结束后快速恢复到原始状态.
或者万一你不想要第二个动画,你可以打电话
yourButton.startAnimation(yourAnimation);
在MotionEvent.ACTION_DOWN内
然后打电话
yourButton.clearAnimation();
在MotionEvent.ACTION_UP中
点击查看更多相关文章
转载注明原文:按下按钮的缩小动画在android中 - 乐贴网