Skip to content

Instantly share code, notes, and snippets.

@eneim
Created July 7, 2014 00:41
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 eneim/798d3ac5b40473b84d01 to your computer and use it in GitHub Desktop.
Save eneim/798d3ac5b40473b84d01 to your computer and use it in GitHub Desktop.
Custom Square ImageView
/**
* A custom {@link ImageView} that is sized to be a perfect square, otherwise
* functions like a typical {@link ImageView}.
*
* @author Andrew Neal (andrewdneal@gmail.com)
*/
public class ENESquareImageView extends ImageView {
/**
* @param context
* The {@link Context} to use
* @param attrs
* The attributes of the XML tag that is inflating the view.
*/
public ENESquareImageView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@Override
public void requestLayout() {
forceLayout();
}
/**
* {@inheritDoc}
*/
@Override
public void onMeasure(final int widthSpec, final int heightSpec) {
super.onMeasure(widthSpec, heightSpec);
final int mSize = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(mSize, mSize);
}
@Override
public void setImageBitmap(Bitmap bm) {
// TODO Auto-generated method stub
super.setImageBitmap(bm);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment