android - StackOverflowError when using ViewCompat -
i'm using viewcompat
compatible animation lower api (10).
but when deploy on emulator stackoverflowerror
this code:
private void fabfadein(){ if (floatingactionbutton.getvisibility() == view.gone) { floatingactionbutton.setvisibility(view.visible); viewcompat.setalpha(floatingactionbutton, 0f); viewcompat.setscalex(floatingactionbutton, 0f); viewcompat.setscaley(floatingactionbutton, 0f); viewcompat.animate(floatingactionbutton) .alpha(1) .scalex(1) .scaley(1) .setduration(300) .setinterpolator(new overshootinterpolator()) .setlistener(new viewpropertyanimatorlistener() { @override public void onanimationstart(view view) { } @override public void onanimationend(view view) { viewcompat.animate(floatingactionbutton).setinterpolator(new linearoutslowininterpolator()).start(); } @override public void onanimationcancel(view view) { } }) .start(); } }
and error:
java.lang.stackoverflowerror @ java.lang.thread.currentthread(thread.java:557) @ java.lang.threadlocal.get(threadlocal.java:59) @ android.view.viewroot.getrunqueue(viewroot.java:3340) @ android.view.view.removecallbacks(view.java:5407) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.removestartmessage(viewpropertyanimatorcompat.java:341) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:268) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.startanimation(viewpropertyanimatorcompat.java:308) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimatorcompatimpl.start(viewpropertyanimatorcompat.java:269) @ android.support.v4.view.viewpropertyanimatorcompat.start(viewpropertyanimatorcompat.java:1249) @ com.test.app.activities.mainactivity$2.onanimationend(mainactivity.java:305) @ android.support.v4.view.viewpropertyanimatorcompat$baseviewpropertyanimat
as can see error goes onanimationend
section of code.
if go sources, see, 1 of realisations of compatible animate
method is:
@override public viewpropertyanimatorcompat animate(view view) { if (mviewpropertyanimatorcompatmap == null) { mviewpropertyanimatorcompatmap = new weakhashmap<>(); } viewpropertyanimatorcompat vpa = mviewpropertyanimatorcompatmap.get(view); if (vpa == null) { vpa = new viewpropertyanimatorcompat(view); mviewpropertyanimatorcompatmap.put(view, vpa); } return vpa; }
so in internal compatible animations use cache of animators attached view. let's return case. have view floatingactionbutton
. , call viewcompat.animate()
it. in internal implementations viewpropertyanimatorcompat
created , assigned view. set
'ing listener it.
after animation finished call animate
again , instead of creating new viewpropertyanimatorcompat
(it seems logicaly) received created viewpropertyanimatorcompat
assigned listener. , have endless loop.
to fix it, need write like:
viewcompat.animate(floatingactionbutton) .alpha(1) .scalex(1) .scaley(1) .setduration(300) .setinterpolator(new overshootinterpolator()) .setlistener(new viewpropertyanimatorlistener() { @override public void onanimationstart(view view) { } @override public void onanimationend(view view) { viewcompat.animate(floatingactionbutton).setinterpolator(new linearoutslowininterpolator()).setlistener(null).start(); } @override public void onanimationcancel(view view) { } }) .start();
in short, need add .setlistener(null)
building animation in onanimationend
callback
Comments
Post a Comment