Created
April 27, 2017 13:05
-
-
Save sergiandreplace/904a388474f99c7b7403727edc907b2f to your computer and use it in GitHub Desktop.
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.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