android - OnClick doesnt work while Animation is running -


i want make game image moves left right , when click on happens. made moving when click on nothing happens. here code:

package com.game.luc08.game;  import android.content.res.resources; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.view.animation.animation; import android.view.animation.translateanimation; import android.widget.imageview; import android.widget.textview;  public class game extends appcompatactivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_game);      final imageview image= (imageview) findviewbyid(r.id.image);      final textview test = (textview) findviewbyid(r.id.test);      int screenwidth = this.getresources().getdisplaymetrics().widthpixels;      image.setonclicklistener(             new view.onclicklistener() {                 @override                 public void onclick(view v) {                     test.settext("clicked");                 }             }     );      animation animation = new translateanimation(0, screenwidth, 0, 0);     animation.setduration(5000);     animation.setfillafter(true);     image.startanimation(animation);  } 

}

instead of animation may try viewpropertyanimator , able detect clicks:

image.animate().xby(screenwidth).setduration(5000).start(); 

Comments