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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:32:09+00:00 2026-06-04T10:32:09+00:00

Got a weird one. I’ve managed a bring it down to a very simple

  • 0

Got a weird one. I’ve managed a bring it down to a very simple example. Really can’t figure it out.

I’ve got a LinearLayout inside a LinearLayout. I want to resize the child using an animation (which I have working a treat, sometimes). Here is my Layout XML.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
        <!-- Lots more controls will appear above -->
        <LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/hello"
                android:gravity="center" />
        </LinearLayout> 
        <!-- Lots more controls will appear below -->
    </LinearLayout>

    <Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />

</LinearLayout>

Now, As you can see, there is a button, and here is the code for that button.

public void btnDoAnimDown_OnClick(View v)
{
    View pnlSlider = findViewById(R.id.animation_subject);
    pnlSlider.measure(1000, 1000);
    DropDownAnim anim = new DropDownAnim(pnlSlider, pnlSlider.getMeasuredHeight(), true);
    anim.setDuration(2000);
    pnlSlider.startAnimation(anim);

    return;     
}

If you were to run it now, it wouldn’t slide down. At all. However, if you were to move the Button into the LinearLayout which I have named Overview and put it after the Child LinearLayout, it works a treat! Like this…

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
        <!-- Lots more controls will appear above -->
        <LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/hello"
                android:gravity="center" />
        </LinearLayout> 
        <!-- Lots more controls will appear below -->
        <Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />
    </LinearLayout>

</LinearLayout>

It now slides down, exactly as expected. Clearly something is going it with the parent layout… As getMeasuredHeight() returns the correct value, it’s just the animation doesn’t actually run!

This is the animation class, am I missing something silly? Probably am!

import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

public class DropDownAnim extends Animation {
    int targetHeight;
    View view;
    boolean down;

    public DropDownAnim(View view, int targetHeight, boolean down) {
        this.view = view;
        this.targetHeight = targetHeight;
        this.down = down;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        int newHeight;
        if (down) {
            newHeight = (int) (targetHeight * interpolatedTime);
        } else {
            newHeight = (int) (targetHeight * (1 - interpolatedTime));
        }
        Log.d("new height", String.valueOf(newHeight));
        view.getLayoutParams().height = newHeight;
        view.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth,
            int parentHeight) {
        super.initialize(width, height, ((View)view.getParent()).getWidth(), parentHeight);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}

Any help would be fantastic!

  • 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-04T10:32:10+00:00Added an answer on June 4, 2026 at 10:32 am

    I don’t know why your code don’t want to do the animation. But I fixed with a little change. What I did is apply the animation to the parent layout and not to the layout that you are transforming.
    Here is the code of the xml, I only added an Id to the parent layout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <LinearLayout android:id="@+id/animation_subject_parent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
            <!-- Lots more controls will appear above -->
            <LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/hello"
                    android:gravity="center" />
            </LinearLayout> 
            <!-- Lots more controls will appear below -->
        </LinearLayout>
            <Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />
    
    </LinearLayout>
    

    And here is the code of the button clic:

    public void btnDoAnimDown_OnClick(View v)
    {
        View pnlSlider = findViewById(R.id.animation_subject);
        View parent = findViewById(R.id.animation_subject_parent);
    
        pnlSlider.measure(1000, 1000);
        DropDownAnim anim = new DropDownAnim(pnlSlider, pnlSlider.getMeasuredHeight(), true);
        anim.setDuration(2000);
    
        parent.startAnimation(anim);
    
        return;     
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a very weird one. I have about a dozen PC's in our
So I've got something really weird going on here, and can't quite put my
Got a weird one here. Site is deployed into production and trying to bring
I've got a weird problem that I can't understand... I have a simple HelloWorld
I've got a really weird problem and I can't seem to find a solution
I have got one weird issue. I am working on an asp .net mvc
I am using mongo db and I got one weird problem when calling to_json
Got a weird bug best shown by this page http://www.zoecormier.com/freelance/ Scroll down to the
I've got some weird behavior and I can only assume is because of the
I got this very weird problem...and it's very important to my...dead line is close...and

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.