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 8948749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:04:37+00:00 2026-06-15T13:04:37+00:00

I have a lot of troubles with Android animation API. I need to animate

  • 0

I have a lot of troubles with Android animation API.

I need to animate image (400px * 600px) on screen (600px * 1024px) from left bottom side to top. Also, big part of image should be located outside of the screen on animation start.

Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/common_background">

<ImageView android:id="@+id/hand"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:scaleType="matrix"
           android:src="@drawable/howto_throw_hand" />

</RelativeLayout>

Activity’s logic:

public class MyActivity extends Activity
{
    ImageView hand;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        hand = (ImageView)findViewById(R.id.hand);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {

        //initial positioning
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                new ViewGroup.MarginLayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT
                )
        );
        layoutParams.setMargins(400, 600, 0, 0);
        hand.setLayoutParams(layoutParams);

        //making animation
        TranslateAnimation animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, -100,
            Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, -1000
        );

        animation.setInterpolator(new LinearInterpolator());
        animation.setDuration(3000);

        //applying animation
        hand.startAnimation(animation);
    }
}

And screenshot with initial state:
enter image description here

The problem is that in the process of animation image is cropped like on this video: video with animation

I missed a lot of time but have not been able to solve the problem =(

What can be done to solve the problem?

Thank you in advance!

~~~~~~~~~~~~~~~~~~ SOLVED ~~~~~~~~~~~~~~~~~~

As ben75 told “… the problem is the initial position. When you do a TranslateAnimation : the image don’t move : it is redraw with a different translation” and “The animation just translate this first cropped image.”

How I solved this:

Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/common_background">

<ImageView android:id="@+id/hand"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:visibility="invisible"
           android:src="@drawable/howto_throw_hand" />

</RelativeLayout>

Activity’s logic:

public class MyActivity extends Activity
{
    ImageView hand;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        hand = (ImageView)findViewById(R.id.hand);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {

        //initial positioning — removed

        //making animation
        TranslateAnimation animation = new TranslateAnimation(400, 300, 600, 0);

        animation.setInterpolator(new LinearInterpolator());
        animation.setDuration(3000);

        //applying animation
        hand.startAnimation(animation);
    }
}

BINGO!

  • 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-06-15T13:04:38+00:00Added an answer on June 15, 2026 at 1:04 pm

    I think the problem is the initial position. When you do a TranslateAnimation : the image don’t move : it is redraw with a different translation.
    The margins specified in your code are such that the image is initially partially out of the screen and so the image is initially cropped. The animation just translate this first cropped image.

    So I would suggest something like this:

        layoutParams.setMargins(0, 0, 0, 0); //left, top are the final position of the image
        hand.setLayoutParams(layoutParams);
    
        //making animation
        TranslateAnimation animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 400, Animation.ABSOLUTE, 0,
            Animation.RELATIVE_TO_SELF, 600, Animation.ABSOLUTE, 0
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some troubles with saving a image from memorystream. Here is my code:
I have been having a lot of troubles with this and I was wondering
I have been running into some troubles recently and I think I need your
Have a lot of troubles on production server. Some routing cause crashing of Application
In our website, some Mac users have troubles when they copy-paste text from PDF
I have been having a lot of troubles with Rails after upgrading to Mountain
I am having a lot of troubles with method overloading here and have no
I have a lot of trouble with the internet connectivity in the program I
I have trouble finding a solution for the following problem: I have a lot
I'm having a lot of trouble with my background worker. I have a background

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.