java - How to set ImageView permanently at a position after TranslateAnimation -


i referenced other questions couldn't find solution, new programming.

so implemented translateanimation on imageview once animation ends returns original position. used override onanimationend doesn't seem work. can figure out should doing?

public class packanimation extends appcompatactivity {      protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.pack_animation);     setrequestedorientation(activityinfo.screen_orientation_landscape);      string s = getintent().getstringextra("choice");       final imageview pandya = (imageview) findviewbyid(r.id.pandya);      final int amounttomoveright = 600;     final int amounttomovedown = 0;      translateanimation anim = new translateanimation(0, amounttomoveright, 0, amounttomovedown);     anim.setduration(100);      anim.setanimationlistener(new translateanimation.animationlistener() {          @override         public void onanimationstart(animation animation) { }          @override         public void onanimationrepeat(animation animation) { }          @override         public void onanimationend(animation animation)         {             relativelayout.layoutparams params = (relativelayout.layoutparams)pandya.getlayoutparams();             params.topmargin += amounttomovedown;             params.leftmargin += amounttomoveright;             pandya.setlayoutparams(params);         }     });      pandya.startanimation(anim); }   } 

you can use anim.setfillafter(true) translateanimation , button stay @ new position, button clicks not work @ new position.

so use viewpropertyanimator or objectanimator. these property animation , change position of view, whereas translateanimation view animation , not change actual property of view.

for example, using viewpropertyanimator:

pandya.animate()     .translationx(amounttomoveright)     .translationy(amounttomovedown); 

refer blog more info:

finally, previous animations changed visual appearance of target objects... didn't change objects themselves. may have run problem. let's want move button 1 side of screen other. you can use translateanimation so, , button happily glide along other side of screen. and when animation done, gladly snap original location. find setfillafter(true) method on animation , try again. time button stays in place @ location animated. , can verify clicking on - hey! how come button isn't clicking? problem animation changes button drawn, not button physically exists within container. if want click on button, you'll have click location used live in. or, more effective solution (and 1 tad more useful users), you'll have write code change location of button in layout when animation finishes.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -