I am developing an application with an animated representation of an image moving to the right from the center. When you click on the image, OnClick () will be called. But when I click on the screen in the path of moving the image (next to the image), OnClick () also turns off. Please tell me how to set the click audience for viewing images only. My code is:
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);
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);
source
share