Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7496243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:32:34+00:00 2026-05-29T18:32:34+00:00

I am doing a project using TranslateAnimation in Android. In that I am translating

  • 0

I am doing a project using TranslateAnimation in Android. In that I am translating images successfully but I have to add onClickListener to the images. That means I have click the images during translating and get their values but I am getting the onClick action on the images.

I am using 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() {

//  Log.e("X1 value     :",String.valueOf(x10));    
//  Log.e("X2 value     :",String.valueOf(x20));    
//  Log.e("Y1 value     :",String.valueOf(y10));    
//  Log.e("Y2 value     :",String.valueOf(y20));    

                    transformAnimation(x10, x20, y10, y20, img, 4000);

                    try {
                        Thread.sleep(4000);
                    } catch (Exception e) {
                    }
//  Message msg=transHandler.obtainMessage();
//  transHandler.sendMessage(msg);
                    x10 = x20;
                    y10 = y20;

                    if (x10 == width) {
                        x20 = width - rand.nextInt(width);
                        y20 = 0;
                    } else if (y10 == 0) {
                        x20 = 0;
                        y20 = height - rand.nextInt(height);
                    } else if (x10 == 0) {
                        x20 = width - rand.nextInt(width);
                        y20 = height;
                    } else if (y10 == height) {
                        x20 = width;
                        y20 = height - rand.nextInt(height);
                    }

                    callTransform();
                }
            };
            thread.start();
        }
    }


    public void transformAnimation(int xFrom, int xTo, int yFrom, int yTo, final ImageView image, int time) {
        TranslateAnimation anim = new TranslateAnimation(xFrom, xTo, yFrom, yTo);
        anim.setDuration(time);
        image.setAnimation(anim);
    }

}

and I tried the following example also – 2D-Tutorial Example.

But in this also I didn’t onClick action for images.

So how to get the onClick action on image during translation?

or

Is there any other way to translate the image with on click action?

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:32:36+00:00Added an answer on May 29, 2026 at 6:32 pm

    during animation the object remains in its original position but it animates translation so you would need to update the Layout Parameters manually during animation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a personal, just for fun, project that is using screen scraping to
I have a small project I am doing in Python using web.py. It's a
I am doing project in powerpoint 2007 automation. In that i am using macro
I m doing a project using eclipse plugin to create a IDE. I have
I am doing a project with VS2010 using C#. I have a local database
I'm doing Project Euler #22: Using names.txt (right click and 'Save Link/Target As...'), a
I am doing a project using PhoneGap + jQuery Mobile in Android. I am
I am doing project using Java and in that I need to reload whole
Hi i am currently doing a school project using cakePHP. I have the following
I am doing asp.net project using C#.I want to display the contents that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.