FloatingActionButton icon animation (Android FAB src drawable animation) -
i trying find documentation how create icon animation of fab's (of design support library), after searching while couldn't find information , animationdrawable reference in android developers doesn't work fab's if class child of imageview.
but manage workaround works fine.
the technic used similar 1 exposed on drawableanimation documentation, , using property animation api doc.
first use valueanimator class, , int array containing ids of drawables you're going use in animation.
final int[] ids = {r.drawable.main_button_1,r.drawable.main_button_2,r.drawable.main_button_3,r.drawable.main_button_4,r.drawable.main_button_5,r.drawable.main_button_6, r.drawable.main_button_7}; fab = (floatingactionbutton) findviewbyid(r.id.yourfabid); valueanimator = valueanimator.ofint(0, ids.length - 1).setduration(youranimationtime); valueanimator.setinterpolator( new linearinterpolator() /*your timeinterpolator*/ );
then set animationupdatelistener, , define change in icon behavior method floatinactionbutton.setimagedrawable(drawable yourdrawable).
yet valueanimator updates default every available frame (depending on load in hardware), don't need redraw icon if drowned why use variable i; once icon has been replace next 1 code wait until time next 1 drowned. (the timing depends on interpolator define)
valueanimator.addupdatelistener(new valueanimator.animatorupdatelistener() { int = -1; @override public void onanimationupdate(valueanimator animation) { int animatedvalue = (int) animation.getanimatedvalue(); if(i!=animatedvalue) { fab.setimagedrawable(getresources().getdrawable(ids[animatedvalue])); = animatedvalue; } } });
also useful when play animation backwards method valueanimator.reverse();
i know not pro solution it's 1 i've figure out work on api's supporting propertyanimation. please if know better solution post here, if not hope post helpful
Comments
Post a Comment