Last active
December 23, 2015 09:19
-
-
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.
This file contains 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
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