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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:37:24+00:00 2026-06-01T20:37:24+00:00

Can someone please explain to a noob the correct way to animate a View

  • 0

Can someone please explain to a noob the correct way to animate a View so its touch area and image actually move together?!

I have read lots of posts and questions and tutorials, but none explains what moves the layout and what moves the image such that I can animate a view and then leave it at its new position.

This is an example method I’m working with, trying lots of different combinations to no success. The view is in the parent RelativeLayout. It’s a touchable menu of icons, and is animated with an xml resource on a click to slide off screen leaving just a little tab showing, where it needs to stay until clicked again.

public void RetractTools (View v){      
    final ImageView finalImage1 = (ImageView) findViewById(R.id.paintsView);
    Animation slideout = AnimationUtils.loadAnimation(this, R.anim.slideout_tools);
    slideout.setFillAfter(true);
    slideout.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            finalImage1.setEnabled(true);
            optionMenu.showing = false;
            optionMenu.inMotion = false;
            finalImage1.layout(1258, 668, 1697, 752);
            finalImage1.setRight(1280);
            finalImage1.invalidate();
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
            finalImage1.setEnabled(false);
        }
    });

    optionMenu.inMotion = true;
    v.startAnimation(slideout);
 }// End RetractMenu

No matter what I try, I encounter problems. setFillAfter does nothing when set in the xml file. Set programmatically, it leaves the image in the right place but the touch controls remain where the menu was. I have tried setLeft and setRight which apparently only move the image, not the view position, and all sorts of different layout options, and fill and no fill and invalidating and not, but can’t solve it. I clearly don’t undersatnd the underlying mechanics needed to position and render a view! 😀

Thanks.

EDIT : Solution

For anyone having similar issues, this is how I have found to work with relative layouts. You create a LayoutParams object with the specified size, and then you can assign it positions. eg.

    final RelativeLayout.LayoutParams position = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);           
    position.leftMargin = 440;

Then assign that to your view

    myView.setLayoutParams(position);

So in summary, you use a LayoutParams object as an interface to your view’s position, rather than accessing the view’s coordinates directly as I assumed.

  • 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-01T20:37:26+00:00Added an answer on June 1, 2026 at 8:37 pm

    What you have is basically fine, with two flaws:

    1. You are using setFillAfter(), which is not especially useful

    2. You are calling layout() and setRight() and stuff, which is not especially effective

    Instead, in onAnimationEnd(), you need to modify the LayoutParams of the View to reflect the new position you want the widget to be in. The size and position of a widget is dictated by the layout rules it negotiates with its container. Initially, those are set via your layout XML resource. By modifying the LayoutParams at runtime, you are changing what those rules are.

    What those LayoutParams are (LinearLayout.LayoutParams, RelativeLayout.LayoutParams, etc.) and what values you should specify in them, we cannot tell you, because we don’t know what you are doing.

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

Sidebar

Related Questions

Excuse the 'noob' question, but can someone please explain the way ASP.NET's buttons work.
Can someone please explain me why its not possible to put a '\0' character
Can someone please explain why ?___SID=U is appearing in some Magento URLs on my
Can someone please explain how Read/Show works.. I cannot find any tutorials on it.
Can someone please explain to me how this responsive approach works? This was done
Can someone please explain to me why the hell? When I try to set
Can someone please explain this phenomenon? I am using Mojarra 2.1.6 - Glassfish 3.1.2.
Can someone please explain to me difference between extends and super in java generics
Can someone please explain with example that I can understand about the difference between
Can someone please explain to me the difference between the AppSettings and ApplicationSettings sections

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.