我想通过 Property Animation 在 ImageButton 上实现缩放功能。例如,当我单击按钮时,它会缩小。当我再次单击它时,它会放大。
这是我的代码的一部分:
OnClickListener clickPlayButtonHandler = new OnClickListener() {
@Override
public void onClick(View v) {
final ImageButton clickedButton = (ImageButton) v;
if((Boolean) v.getTag()) {
// zoom out
clickedButton.animate().setInterpolator(new AnticipateInterpolator()).setDuration(500).scaleXBy(-0.4f).scaleYBy(-0.4f).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
clickedButton.setImageResource(R.drawable.bg_pause);
System.out.println(clickedButton.getWidth()); // output the width of the button for checking
}
@Override
public void onAnimationEnd(Animator animation) {
clickedButton.setTag(false);
int d = clickedButton.getWidth();
System.out.println(clickedButton.getWidth());// output the width of the button for checking
}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) { }
});
} else {
// process zoom in
}
}
};
我在动画开始和动画完成之前打印了按钮的宽度。但是,我发现它们是一样的。我认为当缩小动画完成时,按钮宽度应该比以前小。但它没有。
无法通过 ViewPropertyAnimator 更改视图大小?