1

I'm trying to animate a dialog open from view position. I want that my dialog shows from a button position for example and hides to the same position when dismissed.

this thread Animate a custom Dialog gave me an idea and i came to this xml:

<scale
    android:duration="500"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:pivotX="20%p"
    android:pivotY="20%p"
    android:toXScale="1.0"
    android:toYScale="1.0" />

but i dont know how to dynamically set an start position, cause my button change position.

any idea?

tks a lot....

Community
  • 1
  • 1
JannGabriel
  • 262
  • 3
  • 14
  • possible duplicate of [Show DialogFragment with animation growing from a point](http://stackoverflow.com/questions/13402782/show-dialogfragment-with-animation-growing-from-a-point) – Brais Gabin Mar 12 '14 at 14:04

1 Answers1

2

You can use the method getLocationOnScreen() from the View class to get the current position from the button or any other view you want to use as an anchor.

Edit - Or you may find useful to use instead of Dialog a PopupWindow using the coordinates that you can get through getLocationOnScreen in method showAtLocation().

gunar
  • 14,392
  • 7
  • 54
  • 83
Pozzo Apps
  • 1,739
  • 1
  • 18
  • 27
  • 2
    that wasn't the question. The dialog should be always in center. What I want is to set an open scale animation to this dialog an set the start position to this scale. For example: the dialog will star on position x=20,y=200 and get bigger, and bigger till it`s size on center screen. Got it? – JannGabriel Jun 27 '13 at 18:30
  • Ok, I got, so forget the showAtLocation and use getLocationOnScreen to get the Button position, but you will need to calculate the animation on the fly to get it right. I don't know any ready animation to solve this, sorry. – Pozzo Apps Jun 28 '13 at 11:37
  • That's my problem. Animate on the fly :D . I know it is possible because facebook do that. But still didnt find the way. =/ – JannGabriel Jun 28 '13 at 12:54