我有一个recyclerview,每行包含左图标和文本。点击该行,我尝试使用animationDrawable在imageview上切换图像。动画有效,但点击该行会在不同位置启动动画
protected class ContactViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
@Bind(R.id.contact_name) protected TextView contactNameView;
@Bind(R.id.contact_number) protected TextView contactNumberView;
@Bind(R.id.add_contact_icon) protected ImageView addContactImageView;
private AnimationDrawable animationDrawable;
public ContactViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(this);
}
public void bindContact(Contact contact) {
setContactName(contact.getName());
setContactNumberOrEmail(contact.getNumberOrEmail());
}
@Override public void onClick(View view) {
animationDrawable = (AnimationDrawable) addContactImageView.getDrawable();
animationDrawable.setColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP);
if (animationDrawable.isRunning()) {
animationDrawable.stop();
}
animationDrawable.start();
Contact contact = (Contact) view.getTag();
listener.onContactSelected(contact);
}
}