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

  • Home
  • SEARCH
  • 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 6739499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:29:47+00:00 2026-05-26T11:29:47+00:00

I am using translate animation to make imageview trace a path.Initially I am just

  • 0

I am using translate animation to make imageview trace a path.Initially I am just making my imageview to translate through a particular set of points but it does not.here is my code in ondraw method:

@Override
    public void onDraw(Canvas canvas) {
         Log.w(this.getClass().getName(),"onDraw of Balls called");
      super.onDraw(canvas);
      mCanvas = canvas;



         canvas.drawLine(0, 240, 160, 0, mPaint);
         canvas.drawLine(160, 0, 320, 240, mPaint);

         mBal = (ImageView)findViewById(R.id.strike);
         TranslateAnimation mTrans = new TranslateAnimation(0, 240, 160, 0);
         mTrans.setDuration(6000);
         mTrans.setFillEnabled(true);
         mTrans.setFillAfter(true);
         mTrans.start();

    }

plz help.

=============================================================

Edit 1:-

This is my modified code but the translation is still not working.PLz help

@Override
    public void onDraw(Canvas canvas) {

      Log.w(this.getClass().getName(),"onDraw of Balls called");

      BallsOnDraw(canvas);

    }

     void BallsOnDraw(Canvas canvas)
     {

            canvas.drawLine(0, 240, 160, 0, mPaint);
            canvas.drawLine(160, 0, 320, 240, mPaint);

            TranslateAnimation mTrans = new TranslateAnimation(0, 320, 0,240);

            mTrans.setDuration(6000);
            SitoliaActivity.mBal.startAnimation(mTrans);


     }
  • 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-26T11:29:48+00:00Added an answer on May 26, 2026 at 11:29 am

    You are mixing custom classes with ImageViews and animations. IMHO you should use only one of the methods. Also I don’t see that you actually connect the TranslationAnimation with the ImageView itself.

    So, one solution would be to use TranslateAnimation, but then you would need to call mBal.startAnimation(mTrans) instead of mTrans.start().

    The other solution would be to use a custom view, override onDraw, and handle the animation yourself:

    • save the current time (System.curentTimeMillis)
    • draw the Bitmap directly to the Canvas using canvas.drawBitmap(bitmap, x, y, paint);
    • update the coordinates based on the elapsed time
    • if the animation should still run, call postInvalidateDelayed(40);

    Here is an example custom view:

    public class C extends View {
    
        private static final float FROM_X = 400;
        private static final float FROM_Y = 100;
        private static final float TO_X = 10;
        private static final float TO_Y = 400;
        private static final int DURATION = 2*1000; // 2 seconds
    
        private Bitmap mImage;
        private long mStart = -1;
        private Paint mPaint = new Paint();
    
        public C(Context context) {
            super(context);
            mImage = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.icon)).getBitmap();
        }
    
        @Override
        public void onDraw(Canvas canvas) {
            boolean finished = false;
            if (mStart == -1) {
                // Time to start the animation
                mStart = SystemClock.uptimeMillis();
            }
            int elapsed = (int)(SystemClock.uptimeMillis() - mStart);
            if (elapsed >= DURATION) {
                elapsed = DURATION;
                finished = true;
            }
            float x = FROM_X + (TO_X - FROM_X) * elapsed / DURATION;
            float y = FROM_Y + (TO_Y - FROM_Y) * elapsed / DURATION;
            canvas.drawBitmap(mImage, x, y, mPaint);
            if (!finished) {
                postInvalidateDelayed(10);
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a translate animation: <?xml version=1.0 encoding=utf-8?> <set xmlns:android=http://schemas.android.com/apk/res/android> <translate android:fromXDelta=-75%p android:toXDelta=0%p
How can I programmatically translate an arbitrary view without using an animation ( android.view.animation.*
How can I define this animation xml by java code without using xml <set
Recently working on Speech using microsoft translate. Just wonder if I can request by
I just noticed that now when using Google Translate, the site is updating also
I am making a userscript for facebook that would help translate text using Google
I'm moving a very long image using -webkit-transform: translate(-958px, 0); animation The image gets
I am using a UIView animation to resize and translate a view containing multiple
I'm using Google Translate API, and if I try to translate Mc Donald's this
below is some code I am using to translate a map array into SQL

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.