android - Change alpha of image view by clicking button -
i'm developing android project.
in project have imageview , button. when user clicks on button, want imageview's alpha change 1 0.5 , change 0.5 1.
i wrote following code:
public void animate(imageview imageview) { int animduration = 50; int timebetween = 2; alphaanimation animation1 = new alphaanimation(1, (float) 0.5); animation1.setinterpolator(new accelerateinterpolator()); animation1.setduration(animduration); alphaanimation animation2 = new alphaanimation((float) 0.5, 1); animation2.setinterpolator(new accelerateinterpolator()); animation2.setstartoffset(animduration + timebetween); animation2.setduration(animduration); animationset animation = new animationset(true); animation.addanimation(animation1); animation.addanimation(animation2); animation.setrepeatcount(1); imageview.setanimation(animation); }
and pass imageview function when user clicks on it.
but doesn't work correctly, , nothing changes. problem?
from view.setanimation()
documentation (emphasis mine):
sets next animation play view. if want animation play immediately, use startanimation(android.view.animation.animation) instead. method provides allows fine-grained control on start time , invalidation, must make sure 1) the animation has start time set, , 2) view's parent (which controls animations on children) invalidated when animation supposed start.
although have set start offset animation2
, did not set start time animationset
itself, , view has no idea when start animation.
if want animation start immediately, use startanimation()
instead. if want animations start @ specific time, call setstarttime()
or setstartoffset()
on animationset.
Comments
Post a Comment