Animation on removeAllViews Android -
i have class include layout on button click. included layout has buttons , code executes on clicking these buttons. have used counter indicates number of times button clicked. first time clicking on button includes layout , second time clicking removes views , on. here's code
public class home extends fragment implements onclicklistener { int c = 0; button bmain, bnew, bolder; relativelayout r1; view rootview; animation slidedown, slideup; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rootview = inflater.inflate(r.layout.home, container, false); bmain = (button) rootview.findviewbyid(r.id.btn2); bmain.setonclicklistener(this); return rootview; } @override public void onclick(view arg0) { viewgroup con = null; layoutinflater layoutinflater = (layoutinflater)getactivity().getsystemservice(context.layout_inflater_service); framelayout flcontainer = (framelayout)rootview.findviewbyid(r.id.flcontainer); //loading animation slidedown = animationutils.loadanimation(getactivity(), r.anim.slide_down); slideup = animationutils.loadanimation(getactivity(), r.anim.slide_up); //the counter indicates number of clicks. //needs replaced better solution. //if it's add view if(c%2==0) { //adding layout here flcontainer.addview(layoutinflater.inflate(r.layout.test1,con,false )); //starting animation flcontainer.startanimation(slidedown); //after adding layout can find id of included layout , proceed there bnew = (button) rootview.findviewbyid(r.id.btntest); bnew.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { toast.maketext(getactivity(), "you clicked new", toast.length_long).show(); } }); bolder = (button) rootview.findviewbyid(r.id.btntest1); bolder.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { intent form = new intent(getactivity(),feedbackform.class); startactivity(form); } }); c++; } //if ends here //if it's odd remove view else { flcontainer.removeallviews(); flcontainer.startanimation(slideup); //flcontainer.removeview(flcontainer); //flcontainer.removeview(layoutinflater.inflate(r.layout.test1, con, false)); c++; } } }
the code @ end
flcontainer.removeallviews(); flcontainer.startanimation(slideup);
removes view fails process animation. have tried using removeview in case buttonclicks in if statement fail execute second time. missing here? how can achieve it?
the answer pretty simple. have remove view after animation finished. can achieved pretty simple, first have set animation listener animation , in onanimationend
callback - called when animation finished - remove views.
edit:
replace this:
flcontainer.removeallviews(); flcontainer.startanimation(slideup);
with this:
slideup.setanimationlistener(new animation.animationlistener() { @override public void onanimationstart(animation animation) { } @override public void onanimationend(animation animation) { flcontainer.removeallviews(); } @override public void onanimationrepeat(animation animation) { } }); flcontainer.startanimation(slideup);
if there further problems let me know.
Comments
Post a Comment