开发者

Android LinearLayout Visibility issues with Animation

开发者 https://www.devze.com 2022-12-24 07:51 出处:网络
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 c

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 visibil开发者_StackOverflowity properties, everything works correctly.

What am I missing here?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号