开发者

Android: Animating View position

I'm trying to do something which seems simple. I want to have a map view, with a menu that slides up from the bottom of the screen where settings (for overlay) can be adjusted. However when I use a TranslateAnimation to affect the y position of the LinearLayout (which holds the menu), the buttons in the LinearLayout move, but there "hit area" stays in the same position as they were before the animation.

    TranslateAnimation slide = new TranslateAnimation(0,0,0,0);
 slide.setDuration(300);
 slide.setFillAfter(true);
 pullupMenu.startAnimation(slide);
 mapContainer.startAnimation(slide);

I've also looked into tweening th开发者_如何学Ce view's marginTop value, but haven't even been able to determine how that would be done.

Any help on either of these directions would be much appreciated.


The animation in general is animating the pixels of the widget. My suspicion, based on what you wrote, is that setFillAfter() merely arranges for the pixels to stay in the destination location, not the widget itself.

If you want the animation to actually wind up moving the widget, you need to:

  • Register a listener to find out when the animation ends, and
  • Arrange at that point to modify the layout rules such that the widget actually exists in the new location

You can see a sliding pane that employs this technique here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜