Created
July 7, 2014 00:41
-
-
Save eneim/798d3ac5b40473b84d01 to your computer and use it in GitHub Desktop.
Custom Square ImageView
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
/** | |
* A custom {@link ImageView} that is sized to be a perfect square, otherwise | |
* functions like a typical {@link ImageView}. | |
* | |
* @author Andrew Neal ([email protected]) | |
*/ | |
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