I am doing a project using TranslateAnimation in Android. In this I successfully translate images, but I have to add onClickListener to the images. This means that I click the images during the translation and get their values, but I get the onClick action on the images.
I am using the following code:
public class SampleGame extends Activity implements OnClickListener { int x10, x20, y10, y20; ImageView img; Button animation; Handler transHandler; RelativeLayout layout; Random rand; int mSpeedX, mSpeedY; int width, height; Thread thread; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); layout = (RelativeLayout) findViewById(R.id.layout); animation = (Button) findViewById(R.id.animation); animation.setOnClickListener(this); rand = new Random(); width = getWindow().getWindowManager().getDefaultDisplay().getWidth() - 20; height = getWindow().getWindowManager().getDefaultDisplay().getHeight() - 70; x10 = width - rand.nextInt(width); y10 = height; x20 = width; y20 = height - rand.nextInt(height); thread = new Thread(); img.setOnClickListener(this); } public void onPause() { super.onPause(); thread = null; } @Override public void onClick(View v) { if (v.equals(img)) { Log.e("img clicked :", "yaaaaaaaaa"); } if (v.equals(animation)) { animation.setVisibility(View.INVISIBLE); callTransform(); } } public void callTransform() { if (thread != null) { thread = new Thread() { public void run() {
and I tried the following example: Example of a 2D tutorial .
But in this I also did not do onClick action for images.
So, how to get the onClick action on the image during the broadcast?
or
Is there any other way to translate an image using the click action?
Thanks at Advance.
source share