Android OnTouchListener在按下一个按钮时为所有按钮设置动画
因此,我在ListView中的自定义适配器上有3个按钮。 每当我按下其中一个按钮时,就会触发按钮的动画,每个按钮都有一个Android OnTouchListener在按下一个按钮时为所有按钮设置动画,android,animation,android-animation,ontouchlistener,Android,Animation,Android Animation,Ontouchlistener,因此,我在ListView中的自定义适配器上有3个按钮。 每当我按下其中一个按钮时,就会触发按钮的动画,每个按钮都有一个OnTouchListener,动画在ACTION\u DOWN上按预期工作。但是在ACTION\u UP上,所有三个按钮都是动画,而不仅仅是我单击的按钮。我把Log.I放在侦听器中,它似乎工作正常。还有什么原因可能导致这种情况 下面查找动画和按钮侦听器的代码: //Animation for the buttons final S
OnTouchListener
,动画在ACTION\u DOWN
上按预期工作。但是在ACTION\u 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;
}
});
添加zoom_in.xml和zoom_out.xml@Aci89Done@chiragtalsanaiya