android - Is there a way to use ValueAnimator with a starting point mid-way within the range? -
i have image , wish animate alpha in repeating loop between transparent , visible. easy using valueanimator this:
mvalueanimator1 = valueanimator.offloat(1.0f, 0f); mvalueanimator1.setrepeatmode(valueanimator.reverse); mvalueanimator1.setrepeatcount(valueanimator.infinite); mvalueanimator1.addupdatelistener(new valueanimator.animatorupdatelistener() { @override public void onanimationupdate(valueanimator animation) { float value = ((number) animation.getanimatedvalue()).floatvalue(); imageview.setalpha(value);
that's straightforward if starting alpha image should 1, , straightforward if starting alpha image should 0.
but in case want starting alpha value within range specified within offloat() i.e. if starting alpha should 0.75 want animation loop this:
0.75, 0.85, 0.95, 1.0, 0.95, 0.75, 0.5, 0.3, 0.1, 0.0, 0.1, 0.2, 0.4, 0.6, 0.8 etc
(values representative convey general idea).
is there way of using valueanimator range specified such 0 - 1 starting point mid way within specified range?
you use mvalueanimator1.setcurrentfraction(startingalpha)
set starting point, setcurrentfraction()
added in api 22.
another approach might use animatorset
consisting of 2 valueanimator
objects, first 1 offloat(1.0f)
(the value want animation head first), followed valueanimator
infinitely repeats between 1.0 , 0.0.
Comments
Post a Comment