android - Unable to make view completely GONE after using TranslateAnimation -
i had used translateanimation , slide , down view.
however, realize, though after slide down view, , use view.gone in visibility, view still able receive touch event.
you can produce same problem, clicking on button make orange color view disappear bottom of screen. then, when click on bottom of screen, realize touch event of custom view still being triggered.
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); int color = getresources().getcolor(android.r.color.holo_orange_light); // construct relativelayout final relativelayout customview = new relativelayout(this) { @override public boolean ontouchevent(motionevent event) { this.setpressed(true); log.i("cheok", "oh no! touch!!!!"); return super.ontouchevent(event); } }; customview.setbackgroundcolor(color); final framelayout framelayout = (framelayout)this.findviewbyid(r.id.framelayout); framelayout.addview(customview, new framelayout.layoutparams(framelayout.layoutparams.match_parent, 100, gravity.bottom)); customview.setvisibility(view.gone); button button = (button)this.findviewbyid(r.id.button1); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (customview.getvisibility() != view.visible) { // slide up! translateanimation anim=new translateanimation(0,0,100,0); anim.setfillafter(true); anim.setduration(200); log.i("cheok", "visible!!!"); customview.setvisibility(view.visible); customview.setanimation(anim); customview.setenabled(true); } else { // slide down! translateanimation anim=new translateanimation(0,0,0,100); anim.setfillafter(true); anim.setduration(200); // helpme : not sure why, after hide view sliding down, // making view.gone , setenabled(false), still able // receive touch event. log.i("cheok", "gone!!!"); customview.setvisibility(view.gone); customview.setanimation(anim); customview.setenabled(false); } } }); } } the complete source code demonstrate problem can found here :
https://www.dropbox.com/s/1101dm885fn5hzq/animator_bug.zip
how can make custom view not receive touch event, after had slide down?
it not clear me why using setanimation() instead of startanimation() not appear have set start time on animations.
on note, have found setting view gone while has associated animation not make "gone." instead, must first rid of animation using clearanimation().
so, instead:
public void onclick(view v) { if (customview.getvisibility() != view.visible) { // slide up! translateanimation anim=new translateanimation(0,0,100,0); anim.setfillafter(true); anim.setduration(200); customview.setvisibility(view.visible); customview.setenabled(true); customview.startanimation(anim); } else { // slide down! translateanimation anim=new translateanimation(0,0,0,100); anim.setfillafter(true); anim.setduration(200); anim.setanimationlistener(new animationlistener() { @override public void onanimationend(animation animation) { customview.clearanimation(); customview.setvisibility(view.gone); customview.setenabled(false); } @override public void onanimationrepeat(animation animation) { // nothing } @override public void onanimationstart(animation animation) { // nothing } } } } i don't recall, may have post() contents of onanimationend() instead of running code take effect properly.
Comments
Post a Comment