views:

584

answers:

3

Hello,

I am trying to swap two LinearLayouts by setting their visibility properties to "VISIBLE" and "GONE" respectively. I am also using an animation while the layouts are being swapped. The animation completes successfully and I see the correct layout. However, the previous Layout which has its visibility property set to "GONE" still receives clicks even though it's not visible. At the same time, the layout which is "VISIBLE" receives clicks only when clicked in area where the "GONE" layout isn't clickable. I am also calling the requestFocus method on the "VISIBLE" layout. But it doesn't help.

Moreover, if I skip the animation part and just set the visibility properties, everything works correctly.

What am I missing here?

+2  A: 

If you are animating widgets, you need to make changes to the layout to have the results "stick". Just using the fillAfter stuff will give you some of the effects you see -- it is drawing them in the new location but they aren't really in the new location.

So, I would start by turning off any fill* settings (e.g., fillAfter) in your animation. See what your animation behaves like then. Most likely, it visually will now depict what the clicks tell you.

Then, set up an AnimationListener to get control when the animation ends, and at that point, make real changes to the widgets and their containers to affect your end positions.

Here is a sample project that demonstrates what I mean, albeit in an overly complicated fashion, since I am animating a custom View rather than an off-the-shelf widget.

CommonsWare
Cool. I removed setFillAfter(true) from my animation. And it worked!I am still unclear on what setfillAfter actually does. The sample project you have given seems to be from your book. I was going through it a few days ago and the demo did not work. I will try it again tonight for a better understanding of this issue. Thanks for the help.
adityad
The sample worked the last time I tried it...
CommonsWare
A: 

Hey I'm having a similar problem. I did what you suggested, and the animation behaves as it should, and at the end, I manually change the x and y position in the onAnimationEnd() method. However there is a flash of the old animation just before the position changes. It's almost as if the onAnimationEnd method gets called after a quick repaint in the system. So, you see the old location of the thing your animating for a split second before you can update the position. I've tried setting the visibility to GONE and INVISIBLE, but I still get this flashing behavior. Any ideas on how to solve this problem?

Marcubus
A: 

Tryed to use the panel demo from commonsWare and it didnt work....

Maxrunner