I have several ImageView
s in a RelativeLayout
. now, when user taps any of the ImageView, I want it to be moved to a specified location with subtle animation.
Eg; I have initially set margins for LayoutParams
associated with an ImageView
as layoutparams1.setMargins(90,70,0,0);
and then have it added to the layout.
and when imageview is tapped, I'd like its new location to be 200,200
, with animation.
So, is it possible? if yes, then how?
Note that I have both RelativeLayout
and all of its child ImageView
s created programmatically.
And I'm new to android development so an elaborative answer is expected.
also is better that use
ObjectAnimator
. this move view in new position. for example :UPDATE : The problem is that the
View
is actually still in it's old position. So we have to move it when the animation is finished. To detect when the animation is finished we have to create our ownanimationListener
(inside ouractivity
class):So the
onClickEvent
will get fired again at it's new place. The animation will now move it even more down, so you might want to save thex
andy
in a variable, so that in theonAnimationEnd()
you move it not to a fix location.In below code I am adding a image view in center on frame layout dynamically. After add I am increase scaling and set alpha to give zoom effect and after complete animation I am just translate my image view one position to another position.
Add image view on framelayout
Add animation on image view