Skip to content

Instantly share code, notes, and snippets.

@sergiandreplace
Created April 27, 2017 13:05
Show Gist options
  • Save sergiandreplace/904a388474f99c7b7403727edc907b2f to your computer and use it in GitHub Desktop.
Save sergiandreplace/904a388474f99c7b7403727edc907b2f to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
public class SquareTextView extends android.support.v7.widget.AppCompatTextView {
public SquareTextView(Context context) {
super(context);
}
public SquareTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = this.getMeasuredWidth();
int height = this.getMeasuredHeight();
int size = Math.max(width, height);
int widthSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
int heightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
super.onMeasure(widthSpec, heightSpec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment