• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps TranslateAnimation does not slide proceeding view

vyasrao

Lurker
I have 2 tables, Table-A and Table-B. The Table-B is below Table-A and I am using RelativeLayout.

I set the animation for the Table-A to slide up as follows.

TranslateAnimation slide = new TranslateAnimation(0, 0, 0, -(Table-A Height));
slide.setDuration(500);
slide.setFillAfter(true);
slide.setFillEnabled(true);
slide.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
Table-A.setVisibility(View.GONE);
}
});
Table-A.startAnimation(slide);

The Table-A slides perfectly, but Table-B does not move until the Table-A animation is over and Table-B jumps to the top once the animation is completed. This does not look good as user sees Table-B jumping to the top.

Removing setAnimationListener and adding Table-A.setVisibility(View.GONE); at the bottom will also produce the same result.

Am I doing something wrong? Please help. Thanks in advance.
 
Hi Vyasrao.

The line Table-A.setVisibility(View.GONE); completely treates the placeholder in the RelativeView as if there is NOTHING there at all, so if Table-B has to be below table-A, then it will suddenly jump to the top.
As there is nothing to move table-B, ie no animation set up, then I suggest changing the line to be:
Table-A.setVisibility(View.INVISIBLE);
This will treat the RelativeView as if there is something still there, but invisible, so the table *should* remain unmoved.
This should sort out your problem. :)
 
But I would like the Table-B to slowly move along with Table-A and rest in Table-A position. I don't want it to jump, instead it should move slowly and occupy the Table-A position. Is it not possible?
 
In that case you should create an animation for that table too, just as you have done for table A and run that at the same time. Your code doesn't show that you do that.
 
I have tried that also, I animated both, works great until the animation is over.

Example, if the height of the Table-A is 300, then I set animation for table as 0 to -300.
I set animation of Table-B as 301 to 0. The animation happens smoothly.

But once the animation is over and Table-A visibility is set to GONE, the Table-B also disappears. Probably because Table-B attains position -300. Could not get it work.
 
Also, (Iwas on my phone forthe last comment so I've come online), look at your xml. Is the position of tableA dependant on the pos of tableB or vice-versa? If so, when you are setting one to GONE, like I said in my initial response, the layout will see that as if it is not existing. Fi table A does not exist and table B is in a relative position to table A, then theoretically there will be nowhere for Table B to get put. Whether or not Android will just post it regardless or bomb out is beyond me at this moment as I cannot test it (I am at work).
Hope this helps.
 
Thanks for your help. As you correctly pointed out, Table B is relative to Table A. May be there could be some issue due to that.

I changed the code. There were 2 rows in Table A, and there is a single row in Table B. I made Table B row into 3rd row of Table A. While animation, I calculated the first 2 row heights and animated and set setFillAfter=false and hid the first two rows. This worked as desired. Thanks for your help very much. I appreciate it...
 
Back
Top Bottom