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()。 –