android - Button is not clickable after TranslateAnimation -
android - Button is not clickable after TranslateAnimation -
i'm trying move button (with animation) upon click. want move 100 pixels bottom on first click, 100 pixels on second, 100 pixels bottom on 3rd , on. have simple layout file (main.xml):
<?xml version="1.0" encoding="utf-8"?> <button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="press begin animation" />
my launching activity follows:
public class testactivity extends activity { public final string tag="testactivity"; boolean totop=false; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); button b=(button)findviewbyid(r.id.button); b.setonclicklistener(new onclicklistener() { public void onclick(view v) { toast.maketext(testactivity.this, "left="+v.getleft()+"\nright="+v.getright(), toast.length_short).show(); animation translateanimation; if(totop) translateanimation=new translateanimation(0, 0, 0, -100); else translateanimation=new translateanimation(0, 0, 0, 100); translateanimation.setduration(1000); translateanimation.setfillenabled(true); translateanimation.setfillafter(true); v.startanimation(translateanimation); totop=!totop; } }); } }
when press button, can see moving bottom. when press sec time, nil happens. have click initial rectangle of button begin animation again. seems button drawn expected, actual view remained on same position. want know how can move view entirely, not visual part. besides, utilize toast.maketext.show ensure coordinates of button aren't changed click click.
yes, normal behavior. because animation rerenders view
's pixels, it's position on display remains same. if want relocate view
place animation ends, need phone call view.layout()
method , pass there 4 parameters, describe view
s new position on it's layout. maintain in mind view.layout()
gets params relative view
s parent.
android animation
Comments
Post a Comment