所以我在ListView中的自定义适配器上有3个按钮。
每当我按下其中一个按钮时,按钮就会触发动画,每个按钮都有一个OnTouchListener
,动画在ACTION_DOWN
上按预期工作。但是在ACTION_UP
上,所有三个按钮都会生成动画,而不仅仅是我点击过的按钮。我已将Log.i
置于监听器内,它似乎正常工作。还有什么可能导致这个?
下面找到动画和按钮监听器的代码:
//Animation for the buttons
final ScaleAnimation zoom_in = new ScaleAnimation(1f, 0.9f, 1f, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
final ScaleAnimation zoom_out = new ScaleAnimation(0.9f, 1f, 0.9f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
zoom_in.setFillAfter(true);
zoom_out.setFillAfter(true);
zoom_in.setInterpolator(new DecelerateInterpolator());
zoom_out.setInterpolator(new DecelerateInterpolator());
zoom_in.setDuration(200);
zoom_out.setDuration(200);
final Button likeButton = (Button)convertView.findViewById(R.id.graffiti_like_button);
likeButton.setOnTouchListener(new Button.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// start your first zoom out Animation here
likeButton.startAnimation(zoom_in);
break;
case MotionEvent.ACTION_UP:
// start zoom in animation which returns to original state
likeButton.startAnimation(zoom_out);
break;
case MotionEvent.ACTION_CANCEL:
// start zoom in animation which returns to original state
likeButton.startAnimation(zoom_out);
break;
default:
//v.clearAnimation();
break;
}
return true;
}
});
final Button commentButton = (Button)convertView.findViewById(R.id.graffiti_comment_button);
commentButton.setOnTouchListener(new Button.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// start your first zoom out Animation here
commentButton.startAnimation(zoom_in);
break;
case MotionEvent.ACTION_UP:
// start zoom in animation which returns to original state
commentButton.startAnimation(zoom_out);
break;
case MotionEvent.ACTION_CANCEL:
// start zoom in animation which returns to original state
commentButton.startAnimation(zoom_out);
break;
default:
//v.clearAnimation();
break;
}
return true;
}
});
final Button shareButton = (Button)convertView.findViewById(R.id.graffiti_share_button);
shareButton.setOnTouchListener(new Button.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// start your first zoom out Animation here
shareButton.startAnimation(zoom_in);
break;
case MotionEvent.ACTION_UP:
// start zoom in animation which returns to original state
shareButton.startAnimation(zoom_out);
break;
case MotionEvent.ACTION_CANCEL:
// start zoom in animation which returns to original state
shareButton.startAnimation(zoom_out);
break;
default:
//v.clearAnimation();
break;
}
return true;
}
});