Android Glide library not working with shared element transitions -
i'm looking adopt glide library in place of universal image loader i'm running problem regards shared element transitions.
in simple sandbox i've created following transition using uil: https://dl.dropboxusercontent.com/u/97787025/device-2015-06-18-113333.mp4
pretty simple, , works fine. when used glide, doesn't nice: https://dl.dropboxusercontent.com/u/97787025/device-2015-06-18-114508.mp4
here code i'm using
the first activity:
public class mainactivity extends baseactivity { @override public void oncreate(bundle bundle) { super.oncreate(bundle); setcontentview(r.layout.main); final imageview iv = (imageview) findviewbyid(r.id.main_image); displayimageglide(baseactivity.image_url, iv, true); button button = (button) findviewbyid(r.id.main_button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent(getapplicationcontext(), differentactivity.class); startactivity(intent, iv); } }); } }
and second:
public class differentactivity extends baseactivity { @override public void oncreate(bundle bundle) { super.oncreate(bundle); setcontentview(r.layout.different); imageview imageview = (imageview) findviewbyid(r.id.diff_image); displayimageglide(baseactivity.image_url, imageview, false); } }
baseactivity contains displayimageglide
public void displayimageglide(string url, imageview imageview) { glide.with(this).load(url) .asbitmap().transform(new customtransformation(this)) .skipmemorycache(true) .diskcachestrategy(diskcachestrategy.source) .into(imageview); } private static class customtransformation extends bitmaptransformation { public customtransformation(context context) { super(context); } @override protected bitmap transform(bitmappool pool, bitmap totransform, int outwidth, int outheight) { return bitmapchanger(totransform, outwidth, outheight); } @override public string getid() { return "some_id_1"; } } private static bitmap bitmapchanger(bitmap bitmap, int desiredwidth, int desiredheight) { float originalwidth = bitmap.getwidth(); float originalheight = bitmap.getheight(); float scalex = desiredwidth / originalwidth; float scaley = desiredheight / originalheight; //use larger of 2 scales maintain aspect ratio float scale = math.max(scalex, scaley); matrix matrix = new matrix(); matrix.setscale(scale, scale); //if scaley greater, need center image if(scalex < scaley) { float tx = (scale * originalwidth - desiredwidth) / 2f; matrix.posttranslate(-tx, 0f); } bitmap result = bitmap.createbitmap(desiredwidth, desiredheight, bitmap.getconfig() != null ? bitmap.getconfig() : bitmap.config.argb_8888); canvas canvas = new canvas(result); canvas.drawbitmap(bitmap, matrix, new paint()); return result; }
i've tried removing cache lines glide builder (used prevent caching i'm trying tweak) didn't help. love adopt glide, it's kind of deal breaker if won't work. if has input i'd appreciate it, thanks!
i tried code , got same result, tried implementation following this: https://github.com/codepath/android_guides/wiki/shared-element-activity-transition
and made changes, think key here:
the centercrop should set on imageview, if set glide causes same bug. activity_main.xml
<imageview android:id="@+id/imageview" android:layout_width="match_parent" android:layout_height="150dp" android:layout_centerinparent="true" android:transitionname="detail_image" android:scaletype="centercrop" />
baseactivity.java on mainactivity donttransform should true , on differentactivity false.
public void displayimageglide(string url, imageview imageview, boolean donttransform) { if (donttransform) { glide.with(this).load(url) .skipmemorycache(true) .diskcachestrategy(diskcachestrategy.source) .donttransform() .into(imageview); return; } glide.with(this).load(url) .skipmemorycache(true) .diskcachestrategy(diskcachestrategy.source) .into(imageview); }
edit, see how looks: https://www.dropbox.com/s/30s5l8awxogltls/device-2015-06-23-153153.mp4?dl=0
Comments
Post a Comment