Skip to content

Instantly share code, notes, and snippets.

@koalahamlet
Created April 11, 2014 20:29
Show Gist options
  • Save koalahamlet/10499015 to your computer and use it in GitHub Desktop.
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.
@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