android - Why does scale animation change button size? -
i have few buttons in android app of mine, "start", "stop", , "pause". when start pressed becomes disabled , stop , pause become enabled. similarly, when stop or pause pressed, start becomes enabled again. when these buttons change state, animate change bouncing animation visually indicate user button available. problem animation changing buttons size(background). check out gif see mean (watch stop button):
here code animation:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <scale android:fromxscale="1.0" android:toxscale="1.1" android:fromyscale="1.0" android:toyscale="1.1" android:pivotx="50%" android:pivoty="50%" android:duration="200" android:repeatcount="0" android:repeatmode="reverse" /> </set>
and how i'm applying buttons:
animation scaleanimation = animationutils.loadanimation(this, r.anim.scale_button); startbutton.startanimation(scaleanimation); stopbutton.startanimation(scaleanimation);
why stop button size changing , how can keep doing this?
thanks!
note: set "repeatcount" of animation 1 scale button down. changed 0 debug problem same thing still happening.
i'd refrain using animation
. have play fillenabled
, fillafter
, fillbefore
flags, it's not convenient , non-intuitive api use.
instead, prefer animator
s api.
the animation you'd implement this:
val scalex = objectanimator.offloat(view, view.scale_x, 1.0f, 1.1f).setduration(200) val scaley = objectanimator.offloat(view, view.scale_y, 1.0f, 1.1f).setduration(200) val downscalex = objectanimator.offloat(view, view.scale_x, 1.1f, 1.0f).setduration(200) val downscaley = objectanimator.offloat(view, view.scale_y, 1.1f, 1.0f).setduration(200) val set = animatorset() set.playtogether(scalex, scaley) set.play(downscalex).after(scalex) set.playtogether(downscalex, downscaley) set.start()
or, can play fluent api:
view.animate() .scalexby(0.1f) .scaleyby(0.1f) .setduration(200) .withendaction { view.animate() .scalexby(-0.1f) .scaleyby(-0.1f) .duration = 200 }
Comments
Post a Comment