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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:25:25+00:00 2026-06-16T21:25:25+00:00

I have two views in a RelativeLayout, both of which fill the screen, so

  • 0

I have two views in a RelativeLayout, both of which fill the screen, so view B is on top of view A. I also have an animation defined which can move view B partially offscreen to show view A underneath. The animation works fine, but I’m having the classic issue of the view bounds not moving with the view, so the button that I use to trigger the animation (which is located on view B) is only clickable from its original position, no matter where view B is located. The issue that I’m having is that after the animation ends, when I set the layout params it’s causing view B to be redrawn again, translated from the location of the end of the animation.

As a concrete example, the left edge of view B is initially at x = 0, with a button at x = 450. When the button is pressed, an animation moves the view to x = -400. This works properly – the view is partially off the left hand side of the screen, and the button is now at x = 50, so it is still on screen. The click area for the button though is still at x = 450. So now I set the layout params on view B:

RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) viewB.getLayoutParams();
lp.rightMargin = 400;
viewB.setLayoutParams(lp);

Once the new params are set, the view gets 400px of padding on the right, moving the entire view to x = -800. The clickable area for the button is now properly at x = 50 though, so it seems like I can have it look right or act right. Any idea what I’m doing wrong? Here’s how the animation is set up.

Animation anim = null;
anim = new TranslateAnimation(0, -400, 0, 0);
anim.setAnimationListener(this);
anim.setDuration(duration);
viewB.startAnimation(anim); 
  • 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-16T21:25:26+00:00Added an answer on June 16, 2026 at 9:25 pm

    I was able to get things working by changing the layout params before or after the animation, as appropriate:

    private int marginOffsets;
    
    public void triggerAnimation(boolean show, offset)
    {
        int curX = 0;
        int newX = 0;
        Animation anim = null;
    
        this.showingPanel = show;
        if(show)
        {
            curX = 0 - offset;
    
            android.widget.RelativeLayout.LayoutParams lp = new android.widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,  ViewGroup.LayoutParams.FILL_PARENT);
            lp.rightMargin = 0;
            rootPanel.setLayoutParams(lp);
        }
        else
        {
            newX = 0 - offset;
        }
    
        marginOffsets = newX < 0 ? 0 - offset : offset;
    
        anim = new TranslateAnimation(curX, newX, 0, 0);
        anim.setAnimationListener(this);
        anim.setDuration(duration);
        startAnimation(anim);        
    }
    
    public void onAnimationEnd(Animation anim)
    {
        //This prevents flicker when the view is moving onscreen.
        clearAnimation();
    
        if(!showingPanel)
        {
            //Move the margin to move the actual bounds so click events still work.
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,  ViewGroup.LayoutParams.FILL_PARENT);
            lp.rightMargin = 0 - marginOffsets;
            rootPanel.setLayoutParams(lp);
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two views, both under the NavigationController. I don't want View 1 (on
I have two views, one view takes the whole screen, the second view covers
i have two image views which translates on click. the animation works properly for
I have two views within one .xib (one view for landscape, another for portrait).
I have two views.In first view, I have a table view and I am
I have two views each of which contain two subviews. Hit detection is working
In the asp.net mvc 3 application I have two views which have the same
In My application XML layout, I have one Relativelayout, In which there are two
I have a RelativeLayout view, and 3 children's views too. I'm trying to hide
I have a RelativeLayout in which I have two images. The problem is the

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.