Created
April 11, 2014 20:29
-
-
Save koalahamlet/10499015 to your computer and use it in GitHub Desktop.
how to have picasso load into an image that you're not sure is there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onResume() { | |
super.onResume(); | |
imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
loadImageIfReady(); | |
} | |
}); | |
} | |
private void loadImageIfReady() { | |
if (imageView.getMeasuredWidth() <= 0 || mPayload == null) | |
this.finish(); // if not ready GTFO | |
Picasso.with(this) | |
.load(mPayload) | |
.resize(imageView.getMeasuredWidth(), imageView.getMeasuredWidth()) | |
.centerInside() | |
.into(imageView); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment