Skip to content

Instantly share code, notes, and snippets.

@ridsatrio
Last active December 23, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridsatrio/6de081d5abcf91072242 to your computer and use it in GitHub Desktop.
Save ridsatrio/6de081d5abcf91072242 to your computer and use it in GitHub Desktop.
An squared (width == height) ImageView extension that uses Glide to assist with loading images.
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public final class GlideView extends ImageView {
public GlideView(Context context) {
super(context);
}
public GlideView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GlideView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int width, int height) {
super.onMeasure(width, height);
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
if (measuredWidth > measuredHeight) {
setMeasuredDimension(measuredWidth, measuredWidth);
} else {
setMeasuredDimension(measuredHeight, measuredHeight);
}
}
public void load(String uri) {
Glide.with(getContext()).load(uri).into(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment