单击动画上的事件ImageView仅在起始位置触发

时间:2010-09-20 14:44:23

标签: android animation onclick imageview

机器人:

我有一个带有onClickEvent注册的动画ImageView。我希望ImageView在屏幕上移动,然后单击ImageView。但是当我点击移动的imageView时,没有任何反应。当我单击屏幕的位置时,imageView位于开头的位置,将触发clickEvent。因此,ImageView的实际位置不随动画移动。当有人点击屏幕上正在移动的图像时,有没有人知道如何获取活动?

到目前为止我的代码:

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);
}

}

1 个答案:

答案 0 :(得分:0)

我已经分享了我的解决方案here。希望这会有所帮助。