0

I have a LinearLayout (called layout) with height as fill_parent and an initial top margin of 200dp inside a RelativeLayout. When I clicked a button, I want the topMargin to become 0, expanding the LinearLayout. I am using the next code:

     final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT,
              RelativeLayout.LayoutParams.FILL_PARENT);

     Animation animation = new Animation() {
              @Override
              protected void applyTransformation(float interpolatedTime,
                       Transformation t) {
                       int topMargin = (int)((1-interpolatedTime)*200);
                       layoutParams.setMargins(0, topMargin, 0, 0);
                       layout.setLayoutParams(layoutParams);
                       LogThis.debug("topMargin: "+topMargin);
              }
     };
     animation.setDuration(1000);
     layout.startAnimation(animation);

The problem is that although it makes an animation, it is not soft. It does the transformation in 4 steps, so it does not look good.

Do you have any idea how to make this kind of transformation softly?

Thank you in advance.

EDIT

I have this in the first moment:

enter image description here

And after the animation I want this:

enter image description here

With the TranslationAnimation I get this:

enter image description here

1 Answers1

1

the choppy animation is happening because that's not how the Animation are supposed to be used. Those are to be use Transformation object passed onto the method.

But because you're using a simple translation you can easily achieve that using a TranslateAnimation like on this answer:

translate animation

Community
  • 1
  • 1
Budius
  • 39,391
  • 16
  • 102
  • 144
  • That moves the layout softly, but it does not ocupy the whole space. I need it to grow (resize the layout, not the images inside it). – user1448668 Jun 28 '13 at 15:22