Android:
I have an animated ImageView with onClickEvent registered. I want the ImageView to move around the screen and then click on the ImageView. But when I click on the moving imageView, nothing happens. When I click on the position of the screen where the image was at the beginning, the clickEvent arrow fires. Thus, the actual position of the ImageView does not move with the animation. Does anyone know how to get an event when someone clicks on an image that moves around the screen?
My code is:
public class OnePlayer extends Activity {
private ImageView imageView;
private int points;
private TextView timeTextView;
private TextView pointsTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.oneplayer);
timeTextView = (TextView) findViewById(R.id.time);
timeTextView.setText("01:00");
points = 0;
pointsTextView = (TextView) findViewById(R.id.points);
pointsTextView.setText("0/500");
Animation animation = new TranslateAnimation(0, 100, 0, 200);
animation.setDuration(2000);
animation.setRepeatCount(-1);
animation.initialize(10, 10, 10, 10);
imageView = new ImageView(this);
imageView.setImageResource(R.drawable.plus10);
imageView.setAdjustViewBounds(true);
imageView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
imageView.startAnimation(animation);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.clearAnimation();
v.setVisibility(View.GONE);
points += 10;
pointsTextView.setText(points + "/500");
}
});
RelativeLayout layout = (RelativeLayout) findViewById(R.id.oneplayergame);
layout.addView(imageView);
}
}
source
share