3
Android:ClickEvent動畫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);
}
}
也有同樣的問題:( – Naveed 2012-02-14 19:31:56
你有沒有發現任何解決方案?問題現在太老了 – Naveed 2012-02-14 19:32:43