4
我正在開發一個應用程序,它具有從右向中心移動的動畫圖像視圖。當單擊圖像時,將調用OnClick()。但是,當我點擊圖像移動路徑(接近圖像視圖)屏幕上,然後也OnClick()發射。請告訴我如何設置點擊偵聽器只爲圖像視圖。 我的代碼是:如何爲動畫圖像視圖設置onclick監聽器
ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER);
imageView=new ImageView(getApplicationContext());
imageView.setImageResource(R.drawable.moveimage1);
int width=getWindowManager().getDefaultDisplay().getWidth()/2;
System.out.println("width==="+width);
moveLefttoRight = new TranslateAnimation(width, 0, 0, 0);
moveLefttoRight.setDuration(3000);
moveLefttoRight.setRepeatCount(TranslateAnimation.INFINITE); // animation repeat count
moveLefttoRight.setRepeatMode(2);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_LONG).show();
System.out.println("Clicked");
}
});
imageView.startAnimation(moveLefttoRight);
ll.addView(imageView);
setContentView(ll);
你想要onClick()在圖像視圖動畫或動畫完成後觸發,這意味着什麼 – San
L1 linearLayout中的imageview是什麼? – Amrut
我想單擊時觸發onClick()。 –