android - makeSceneTransitionAnimation between two recyclerViews working only in reverse -
in short :
creating shared element activity transition between fragment recyclerview onclick opening activity recylcerview not trigger transition.
however, using supportfinishaftertransition();
close opened activity does trigger animation correctly (it goes backwards previous activity).
also, creating shared elements outside recyclerview cause animation work @ every case (both forwards , backwards on finish) - therefore code must correct.
viewholder onclicklistener opens activity - simplified reduce useless code.
public class statsviewholder extends webstatsviewholder implements view.onclicklistener{ protected textview vtitle; protected imageview vpicture; public statsviewholder (view itemview) { super(itemview); vtitle = (textview) itemview.findviewbyid(r.id.stats_title); vpicture = (imageview) itemview.findviewbyid(r.id.stats_picture); vtitle.setclickable(true); vtitle.setonclicklistener(this); } @override public void onclick(view v) { if (mitemclicklistener != null) { mitemclicklistener.onitemclick(v, getlayoutposition(), v.getrootview()); } } }
clicking title opens new activity. - animation not trigger unless put target outside of recycler
madapter.setonitemclicklistener(new mysteamwebstatsadapter.onitemclicklistener() { @override public void onitemclick(view view, int position, view parent) { intent intent = new intent(getactivity(), details.class); activityoptions options = activityoptions.makescenetransitionanimation(getactivity(), parent.findviewbyid(r.id.stats_picture), "stats_picture"); startactivity(intent, options.tobundle()); }
turns out i'm stupid, leaving in case makes same mistake.
in target recyclerview
using picasso load drawable - time picasso needed load image time animation took , therefore didn't show up. that's reason why animation worked in reverse - image cached.
how solve issue :
wait until image loaded - called in oncreate
if (build.version.sdk_int >= build.version_codes.lollipop) { postponeentertransition(); }
request callback picasso when image loaded
picasso.with(this).load(mapobject.getdrawable()).transform(new circletransform()).fit().centercrop().into(detailpicture, new callback() { @override public void onsuccess() { schedulestartpostponedtransition(detailpicture); } @override public void onerror() { } });
start animation
private void schedulestartpostponedtransition(final view sharedelement) { sharedelement.getviewtreeobserver().addonpredrawlistener( new viewtreeobserver.onpredrawlistener() { @override public boolean onpredraw() { sharedelement.getviewtreeobserver().removeonpredrawlistener(this); startpostponedentertransition(); return true; } }); }
Comments
Post a Comment