Android - Animation movement of container does not

2019-07-25 11:34发布

问题:

So I have an application running on Android 2.2 (on a HTC desire). When the user presses the menu key, my menus silkily slide in from top and bottom. This works just great. Or so I thought. It turns out that even when the ImageButtons are off screen and invisible, the hitboxes of the places where they were before I moved them out of sight activate the buttons.

I have tried:

_top_slide_out_menu.forceLayout();
_top_slide_out_menu.recomputeViewAttributes(_measure);
_top_slide_out_menu.computeScroll();

No difference. At a guess it may be because I am moving the parent container object using the animation rather than the buttons themselves. I can only hypothesise that there is a bug that does not update the child hitboxes. This bug seems to also affect subsequent animations I apply to the button. I have a animation I run on a button that I have previously moved using a different animation. This second animation shrinks then grows the button to give the impression of a click. Only half of the button is redrawn, as that is the half contained within the area of the origional button location.

So the question is, has anyone run into this? Is there anything to try other than moving all the buttons individually (which would get rather tiresome)?

I'd appreciate any ideas at this point!

Thanks

回答1:

Android animations only shifts the pixels of the UI controls when you add animations to them. To actually update the layout after the animation, you should implement an animation listener and manually update the layout other wise the old layout will still remain with the only the pixels shifted.