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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:25:49+00:00 2026-06-11T05:25:49+00:00

I have done the layout expand animation with the following code. It works fine

  • 0

I have done the layout expand animation with the following code. It works fine when we invoke the animation by clicking a text view, but the same is not happening when I try to do that by clicking a layout. Can anyone help me in solving this?

LinearLayout hello= (LinearLayout)findViewById(R.id.lin_hello);
final RelativeLayout rel=(RelativeLayout)findViewById(R.id.rel_nah_hide);
hello.setOnClickListener(new OnClickListener() {        
    @Override
    public void onClick(View v) {
        expand=!expand;
        Animation a=expand(rel, expand);
        rel.setAnimation(a);
        a.start();
    }
});

public static Animation expand(final View v, final boolean expand) {
    try {
        Method m = v.getClass().getDeclaredMethod("onMeasure", int.class, int.class);
        m.setAccessible(true);
        m.invoke(v,
                 MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                 MeasureSpec.makeMeasureSpec(((View)v.getParent()).getMeasuredWidth(), MeasureSpec.AT_MOST)
        );
    } catch (Exception e) {
        e.printStackTrace();
    }

    final int initialHeight = v.getMeasuredHeight();

    if (expand) {
        v.getLayoutParams().height = 0;
    } else {
        v.getLayoutParams().height = initialHeight;
    }
    v.setVisibility(View.VISIBLE);

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            int newHeight = 0;
            if (expand) {
                newHeight = (int) (initialHeight * interpolatedTime);
            } else {
                newHeight = (int) (initialHeight * (1 - interpolatedTime));
            }
            v.getLayoutParams().height = newHeight;
            v.requestLayout();

            if (interpolatedTime == 1 && !expand)
                v.setVisibility(View.GONE);
        }

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

    a.setDuration(SPEED_ANIMATION_TRANSITION);
    a.setAnimationListener(new AnimationListener(){
        @Override
        public void onAnimationEnd(Animation arg0) {
            animWorkingFlag=false;
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onAnimationStart(Animation animation) {
            animWorkingFlag=true;
        }
    });

    return a;
}

and following is the xml layout,

<?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:id="@+id/lin_hello"
        android:layout_height="50dp"
        android:layout_width="fill_parent"
        android:orientation="vertical">
        <TextView 
            android:id="@+id/hello"
            android:layout_height="50dp"
            android:layout_width="fill_parent"
            android:text="Nah"
            android:gravity="center"
            android:background="#F03535"/>
    </LinearLayout>

    <RelativeLayout 
        android:id="@+id/rel_nah_hide"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <TextView 
            android:id="@+id/txt_nah_hide1"
            android:layout_height="50dp"
            android:layout_width="fill_parent"
            android:text="Incorrect Name/Address"
            android:gravity="center"
            android:textColor="@color/white"/>
        <TextView 
            android:id="@+id/txt_nah_hide2"
            android:layout_height="50dp"
            android:layout_width="fill_parent"
            android:text="Venue is closed"
            android:gravity="center"
            android:textColor="@color/white"
            android:layout_below="@id/txt_nah_hide1"/>
        <TextView 
            android:id="@+id/txt_nah_hide3"
            android:layout_height="50dp"
            android:layout_width="fill_parent"
            android:text="Venue is duplicate"
            android:gravity="center"
            android:textColor="@color/white"
            android:layout_below="@id/txt_nah_hide2"/>
    </RelativeLayout>

    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="28dp"
        android:text="heelo2222"/>
</LinearLayout>
  • 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-11T05:25:50+00:00Added an answer on June 11, 2026 at 5:25 am

    Use next part code: ->

    View hello= findViewById(R.id.lin_hello);
    final RelativeLayout rel=(RelativeLayout)findViewById(R.id.rel_nah_hide);
    hello.setOnClickListener(new OnClickListener() {        
        @Override
        public void onClick(View v) {
            expand=!expand;
            Animation a=expand(rel, expand);
            rel.setAnimation(a);
            a.start();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done a couple of simple swing based apps with static layout, but
I have done an layout in my GUI but it did not work ,
I have done split view using 'hbox' layout, as below: Ext.define('Sencha.view.Blog', { extend: 'Ext.Panel',
I have a class that extends android.app.Dialog, the layout is done in an xml
I have done an email approval script following James Ferreira's youtube tutorial here .
I'm trying to create a simple username/password login screen. I have the layout done,
To accomplish this I have done this: <table style=width:100%;> <tr> <td style=width:50%;text-align: left;>left</td> <td
At a high level, I have done several types of progress bar styles, but
I have done this before, but still haven't mastered it. I downloaded a font
I have done something less brilliant but no matter how much i check in

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.