Expand/collapse RelativeLayout

Put your problem here if it does not fit any of the other categories.

Expand/collapse RelativeLayout

Postby IKEE » Sat Sep 17, 2011 12:27 pm

Hi, I found a code snippet to expanding and collapsing views using animation (just like in the Gmail app when muting a conversation). The problem is, I don't know how to start the animation. And what do I put in the Transformation parameter?

anim.java:
Code: Select all
class DropDownAnim extends Animation{
    int targetHeight;
    RelativeLayout v;
    boolean down;

    public DropDownAnim(RelativeLayout wv,  boolean d){
        v = wv;
        targetHeight = 100;
        down = d;
    }


    protected void applyTransformation(float interpolatedTime, Transformation t){
        int newHeight;
        if(down){
              newHeight = (int)(targetHeight*interpolatedTime);
        }
        else{
              newHeight = (int)(targetHeight*(1-interpolatedTime));
        }
        v.getLayoutParams().height = newHeight;
        v.requestLayout();
    }

    public void initalize(int width, int height, int parentWidth, int parentHeight){
        super.initialize(width,height,parentWidth,parentHeight);

    }

    public boolean willChangeBounds(){
        return true;
    }
}


a portion of my mainactivity.java:
Code: Select all

   public void onClick(View arg0) {
      // TODO Auto-generated method stub
      switch(arg0.getId()){
      case R.id.undo:
         DropDownAnim anim = new DropDownAnim(rl, false);
      }
   }


So I don't know how to use the snippet. Can anyone help me? The original Stackoverflow thread and explanation and how to use the code is here: http://stackoverflow.com/questions/4946295/android-expand-collapse-animation/5122460#5122460 . Thanks.
IKEE
Freshman
Freshman
 
Posts: 2
Joined: Mon Sep 12, 2011 2:46 pm

Top

Re: Expand/collapse RelativeLayout

Postby jonbonazza » Sat Sep 17, 2011 3:32 pm

You need to make a call to startAnimation(anim);
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Expand/collapse RelativeLayout

Postby IKEE » Sat Sep 17, 2011 7:11 pm

jonbonazza wrote:You need to make a call to startAnimation(anim);


Eclipse gives me an error. There's no such method.
IKEE
Freshman
Freshman
 
Posts: 2
Joined: Mon Sep 12, 2011 2:46 pm

Re: Expand/collapse RelativeLayout

Postby jonbonazza » Mon Sep 19, 2011 3:24 pm

It's a method of the View class, so you need to create a View object (most likely an ImageView in your case) and call the method from the ImageView.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 24 guests