Skip to content

Instantly share code, notes, and snippets.

@dominicthomas
Created September 2, 2014 12:06
Show Gist options
  • Save dominicthomas/b51ccd9e83103daf9b78 to your computer and use it in GitHub Desktop.
Save dominicthomas/b51ccd9e83103daf9b78 to your computer and use it in GitHub Desktop.
Creates an imagebutton that will always have a height that matches the width. Useful if displayed in a row in a horizontal linear layout.
public class SquareImageButton extends ImageButton {
public SquareImageButton(Context context) {
this(context, null);
}
public SquareImageButton(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SquareImageButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment