animation - Android view flickering at the beginning TranslateAnimation -
i use translateanimation move buttons , works fine, before animation started strange flickering apear. short time animated view moves position higher is. after view normal position , animation started.
i use relativelayout , move 7 buttons.
public void moveview(final int rotationtype) { animationset animationlist[] = new animationset[buttonamount]; (int = 0; < buttonamount; i++) { animationset animationsset = new animationset(false); animationsset.setfillafter(true); boolean visible = true; boolean hide = false; boolean show = false; imagebutton button = buttons.get(i); int position = + movementcount; if (position < 0) { position = getlastbuttonid(); } else if (position > getlastbuttonid()) { position = position - buttonamount; } int cl = getdp(leftcoord.get(position)); int cb = getdp(bottomcoord.get(position)); // todo left right if (rotationtype == rightbutton) { position--; } else if (rotationtype == leftbutton) { position++; } if (position < 0) { position = getlastbuttonid(); } else if (position > getlastbuttonid()) { position = position - buttonamount; } int nl = getdp(leftcoord.get(position)); int nb = getdp(bottomcoord.get(position)); int left = cl - nl; int bot = cb - nb; long time = 1000; if (rotationtype == leftbutton) { if (cl == getdp(leftarrowleft) && cb == getdp(leftarrowbottom)) { hide = false; visible = true; show = true; } if (nl == getdp(leftarrowleft) && nb == getdp(leftarrowbottom)) { hide = false; visible = false; time = 0; } if (nl == getdp(rightarrowleft) && nb == getdp(rightarrowbottom)) { hide = true; } } else if (rotationtype == rightbutton) { if (cl == getdp(rightarrowleft) && cb == getdp(rightarrowbottom)) { hide = false; visible = true; show = true; } if (nl == getdp(leftarrowleft) && nb == getdp(leftarrowbottom)) { hide = true; } if (nl == getdp(rightarrowleft) && nb == getdp(rightarrowbottom)) { hide = false; visible = false; show = false; time = 0; } } translateanimation trans = new translateanimation(left, 0, bot, 0); final int l = nl; final int b = nb; final imagebutton ib = button; final boolean isvisible = visible; final boolean ishide = hide; final boolean isshow = show; final int count = i; final relativelayout layout = main; button.clearanimation(); trans.setanimationlistener(new animationlistener() { relativelayout.layoutparams params; @override public void onanimationstart(animation animation) { params = new relativelayout.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content); params.leftmargin = l; params.topmargin = b; ib.setlayoutparams(params); if (isvisible) { int tag = (integer) ib.gettag(); ib.setimageresource(resourceslist[tag]); } } @override public void onanimationrepeat(animation animation) { } @override public void onanimationend(animation animation) { if (!isvisible) { ib.setimagedrawable(null); } } }); trans.setduration(time); animationsset.addanimation(trans); if (show) { animation animshow = new alphaanimation(.0f, 1f); animshow.setanimationlistener(new animationlistener() { @override public void onanimationstart(animation animation) { // todo auto-generated method stub } @override public void onanimationrepeat(animation animation) { // todo auto-generated method stub } @override public void onanimationend(animation animation) { // ib.setvisibility(view.visible); // buttons.get(count).setvisibility(view.visible); } }); animshow.setduration(1000); animationsset.addanimation(animshow); } else if (hide) { animation hideshow = new alphaanimation(1.0f, .0f); hideshow.setanimationlistener(new animationlistener() { @override public void onanimationstart(animation animation) { // todo auto-generated method stub } @override public void onanimationrepeat(animation animation) { // todo auto-generated method stub } @override public void onanimationend(animation animation) { } }); hideshow.setduration(1000); animationsset.addanimation(hideshow); } button.startanimation(animationsset); } if (rotationtype == rightbutton) { movementcount--; } else if (rotationtype == leftbutton) { movementcount++; } if (movementcount < 0) { movementcount = getlastbuttonid(); } else if (movementcount > getlastbuttonid()) { movementcount = 0; } }
Comments
Post a Comment