Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the 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.

like image 862
karnage Avatar asked Feb 03 '10 21:02

karnage


People also ask

How can I dynamically set the position of view in android?

This example demonstrates how do I in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2− Add the following code to res/layout/activity_main. xml.

How do I animate a view in android?

You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.

What are the two different types of view animations?

There are two types of animations that you can do with the view animation framework: Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation. Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable .

What is twined animation in android?

Tween animations are a specific type of animation related to rotation, sliding, and movement of an object.


1 Answers

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.

like image 174
CommonsWare Avatar answered Sep 22 '22 08:09

CommonsWare