android - Shared Element Transition and Fresco not working properly -
i have 2 activities, both of contain image. using fresco load image in 1 activity , picasso load image in activity. here relevant parts of code:
image in first activity
<com.facebook.drawee.view.simpledraweeview android:id="@+id/imageview102" android:transitionname="image" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginleft="9dp" android:layout_marginright="9dp" android:layout_margintop="10dp" fresco:actualimagescaletype="centercrop" fresco:placeholderimage="@color/wait_color" fresco:placeholderimagescaletype="fitcenter" fresco:viewaspectratio="1.33" android:layout_marginbottom="10dp" />
image in second activity
<uk.co.senab.photoview.photoview android:id="@+id/zoomable" android:transitionname="image" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerinparent="true" />
i using photoview in second activity zoom in , zoom out image.
first activity
uri uri = uri.parse(photourl); imagerequest request = imagerequestbuilder.newbuilderwithsource(uri) .setprogressiverenderingenabled(true) .build(); draweecontroller controller = fresco.newdraweecontrollerbuilder() .setimagerequest(request) .setoldcontroller(image.getcontroller()) .build(); image.setcontroller(controller); image.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intent intent = new intent(imageactivity.this, alternatefullimageactivity.class); intent.putextra("id", photoid); intent.putextra("photourl", photourl); if (build.version.sdk_int >= build.version_codes.lollipop) { activityoptionscompat options = activityoptionscompat. makescenetransitionanimation(imageactivity.this, (view)image, "image"); startactivity(intent, options.tobundle()); } else { startactivity(intent); } } });
second activity
intent intent = getintent(); photoid = intent.getextras().getstring("id"); photourl = intent.getextras().getstring("photourl"); picasso.with(alternatefullimageactivity.this) .load(photourl) .into(image); mattacher = new photoviewattacher(image);
the problem is, transition not smooth , fast. read here need change transition changebounds
. how change transition , how add duration transition say, 1000ms?
you can create class extends transitionset specify transitions, changebounds. example...
@targetapi(build.version_codes.lollipop) public class detailtransition extends transitionset { public detailstransition(int duration, int delay) { setordering(ordering_together); addtransition(new changebounds()). addtransition(new changetransform()). addtransition(new changeimagetransform()).setduration(duration).setstartdelay(delay).setinterpolator(new anticipateovershootinterpolator()); } }
and set shared element transition onto fragment or activity / window. fragments this
currentfragment.setsharedelemententertransition(new detailstransition(1000, 400));
or activity this
getwindow().setsharedelemententertransition(new detailstransition(1000, 400));
Comments
Post a Comment