Last active
September 24, 2015 01:40
-
-
Save marcelocra/846e6197f78b7ca86b2a to your computer and use it in GitHub Desktop.
Access ImageView info when using Picasso library
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
// This can be used to load images when you don't know their sizes beforehand. | |
imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
// Need to remove the listener, otherwise weird things will happen. | |
if (Build.VERSION.SDK_INT < 16) { | |
imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this); | |
} else { | |
imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this); | |
} | |
Picasso.with(mContext) | |
.load(mImageUrls.get(position)) | |
// The dimension you leave with value 0 will be set based on the view size. | |
.resize(imageView.getWidth(), 0) | |
.into(imageView); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment