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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:14:07+00:00 2026-06-09T22:14:07+00:00

I have a LinearLayout that I use as a container for some buttons and

  • 0

I have a LinearLayout that I use as a container for some buttons and textview’s that I would like to animate the height of to give an impression of the layout sliding down when the user presses a “show” button.

I have set the LinearLayout to layout_height=”0dp” and visibility=”gone” in my xml. I then wish to set it to be visible and whatever height is need to wrap the content. At the moment I’m having issues even animating it at all, nevermind the wrap content height.

Here’s my method for animating:

private void toggle(final LinearLayout v) {
    v.setVisibility(View.VISIBLE);
    ValueAnimator va = ValueAnimator.ofInt(0, 300);
    va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            v.getLayoutParams().height = value.intValue();
            v.invalidate();

        }
    });

    va.start();
}

Perhaps the problem is how I am setting the height of the LinearLayout? Or am I misunderstanding the function of the ValueAnimator? I’ve looked around at the blog post’s by Chet Haase but they do not contain any specific height animation examples. Neither have I been able to find and good examples of how to work with animations of height using API’s from 3.0+. Would love some help on this, thanks!

  • 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-09T22:14:09+00:00Added an answer on June 9, 2026 at 10:14 pm

    Looking at this blog post: http://tech.chitgoks.com/2011/10/29/android-animation-to-expand-collapse-view-its-children/ I found that I shouldn’t use view.invalidate() to have the layout redrawn. I should use view.requestLayout().

    Thus the code becomes something like this:

    ValueAnimator va = ValueAnimator.ofInt(0, height);
        va.setDuration(700);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                Integer value = (Integer) animation.getAnimatedValue();
                v.getLayoutParams().height = value.intValue();
                v.requestLayout();
            }
        });
    

    I just wanted to add a note on how to get the height of the LinearLayout as well to make the animation dynamic. To get the height all the views need to be drawn first. Therfor we have to listen for an event that tells us that the drawing is done. This can be done from the onResume() method like this (note that in my xml I have declared the container to wrap_content for height and it is also visible, since I want to hide it from the start I do that efter measuring it):

    @Override
        public void onResume() {
            super.onResume();
            final ViewTreeObserver vto = filterContainer.getViewTreeObserver();
            vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    height = filterContainer.getHeight();
                    filterContainer.setVisibility(View.GONE);
                    filterContainer.getLayoutParams().height = 0;
                    filterContainer.requestLayout();
                    ViewTreeObserver obs = filterContainer.getViewTreeObserver();
                    obs.removeGlobalOnLayoutListener(this);
                }
            });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large png that I would like to use as a background
I have a LinearLayout that I would like to change the background color of
I have a Linear Layout that has a Button and a TextView on it.
I have a LinearLayout which holds a couple of buttons. To give the user
I have a drawable that i use as a Background for a LinearLayout. I
I have a large header image that I'd like to use for both tablet
I have this custom layout: - LinearLayout - FrameLayout - ImageView - TextView This
I have a layout I want to reuse, it looks like: <LinearLayout .. >
I have a code that should get a LinearLayout (with more LinearLayout's inside), and
There is one image on LinearLayout. I have to move that image in any

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.