0

I have a View inside a RelativeLayout, and I managed to perform some animations to alter its position. Now I need the reversed animation that restore the view to its original position. Is there a way I can calculate the view's position according to its layout parameters?

PS: I can do this by storing the initial position into a variable, but I don't really want to introduce another state variable for something that could be calculated on the fly (in theory at least).

Khanh Nguyen
  • 11,112
  • 10
  • 52
  • 65
  • "I don't really want to introduce another state variable for something that could be calculated on the fly" - This seems ridiculously unnecessary to me. Why is trying to calculate the original position from possibly widely varying parameters preferable to maintaining a PointF field, or two floats? – Mike M. Aug 07 '14 at 01:52
  • @MikeM. If the original position *can* be calculated, there would be a solution much simpler than introducing a new state variable (not the most efficient though). Yeah if one is lazy, he could just go with PointF instead of posting a question. My point here is to know if this is possible at all, since the calculations are obviously doable, it's just a matter of whether Android SDK exposes it or not. – Khanh Nguyen Aug 07 '14 at 02:23
  • I found a useful answer here. Hope it would be hepful. http://stackoverflow.com/questions/6535648/how-can-i-dynamically-set-the-position-of-view-in-android – chathura Aug 07 '14 at 02:46
  • 1
    I still don't understand what you're getting at, as _in no way_ is any calculation "much simpler" than retrieving stored values, but you might have a look here: http://stackoverflow.com/questions/4120824/android-reversing-an-animation – Mike M. Aug 07 '14 at 02:50
  • 1
    @MikeM. Thanks, not exactly what I am after, but the link *did* really help. By "simpler" I mean in terms of OOP design, not efficiency. Similarly, if a property can be inferred from the object's other properties, it should be implemented as a method that actually repeats the calculations whenever someone calls it, rather than as a stored variable. IMHO, less states means less errors, but it could be just my preference. – Khanh Nguyen Aug 07 '14 at 03:25

0 Answers0