@@ -73,6 +73,8 @@ public class EasyTextView extends TextView {
7373 private TypedValue textValue ;//左右文字支持xml中设置iconFont
7474 //icon的index
7575 private int iconIndex = 0 ;
76+ //是否开启计算文字边界,开启后会以最大文字大小为View高度,并且会增加部分文字高度,防止部分英文类型y,g由于基线的原因无法显示完全
77+ private boolean autoMaxHeight = false ;
7678
7779 public EasyTextView (Context context ) {
7880 this (context , null );
@@ -135,7 +137,8 @@ private void initIconFont() {
135137
136138 if (!TextUtils .isEmpty (mTextRight )) {
137139 AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan ((int ) mTextPadding );
138- stringBuilder .setSpan (sizeSpan , iconIndex + centerSize , iconIndex + centerSize + 1 , Spanned
140+ stringBuilder .setSpan (sizeSpan , iconIndex + centerSize , iconIndex +
141+ centerSize + 1 , Spanned
139142 .SPAN_EXCLUSIVE_EXCLUSIVE );
140143 }
141144
@@ -196,7 +199,8 @@ private void initIconFont() {
196199 for (SpanContainer container : rightContainer ) {
197200 for (Object o : container .spans ) {
198201 try {
199- stringBuilder .setSpan (o , start + container .start , start + container .end , container .flag );
202+ stringBuilder .setSpan (o , start + container .start , start + container .end ,
203+ container .flag );
200204 } catch (Exception e ) {
201205 //please check invoke clearSpan() method first
202206 }
@@ -269,7 +273,8 @@ private void setLeftTextAttr(SpannableStringBuilder stringBuilder) {
269273 }
270274 }
271275
272- private void initTextSize (SpannableStringBuilder stringBuilder , int start , int end , float textSize , int mCurColor ) {
276+ private void initTextSize (SpannableStringBuilder stringBuilder , int start , int end , float
277+ textSize , int mCurColor ) {
273278 if (textSize != 0 ) {
274279 CharacterStyle sizeSpan ;
275280 final int gravity = getGravity () & Gravity .VERTICAL_GRAVITY_MASK ;
@@ -297,7 +302,8 @@ private void initTextLeftColor(SpannableStringBuilder stringBuilder, int end) {
297302 }
298303 }
299304
300- private void initTextStyle (int textStyle , SpannableStringBuilder stringBuilder , int start , int end ) {
305+ private void initTextStyle (int textStyle , SpannableStringBuilder stringBuilder , int start ,
306+ int end ) {
301307 StyleSpan span ;
302308 if (textStyle != Typeface .NORMAL ) {
303309 span = new StyleSpan (textStyle );
@@ -376,6 +382,7 @@ private void initAttr(Context context, AttributeSet attrs) {
376382 mTextLeftStyle = array .getInt (R .styleable .EasyTextView_textLeftStyle , Typeface .NORMAL );
377383 mTextRightStyle = array .getInt (R .styleable .EasyTextView_textRightStyle , Typeface .NORMAL );
378384 mTextCenterStyle = array .getInt (R .styleable .EasyTextView_textCenterStyle , Typeface .NORMAL );
385+ autoMaxHeight = array .getBoolean (R .styleable .EasyTextView_autoMaxHeight , false );
379386 array .recycle ();
380387 }
381388
@@ -730,4 +737,17 @@ public EasyTextView build() {
730737 init ();
731738 return this ;
732739 }
740+
741+ @ Override
742+ protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
743+ super .onMeasure (widthMeasureSpec , heightMeasureSpec );
744+ if (autoMaxHeight ) {
745+ int lead = 0 ;
746+ if (getPaint () != null ) {
747+ lead = getPaint ().getFontMetricsInt ().leading * 3 ;
748+ }
749+ setMeasuredDimension (getMeasuredWidth (), (int ) (Math .max (getMeasuredHeight (), Math .max
750+ (mLeftSize , mRightSize )) + lead ));
751+ }
752+ }
733753}
0 commit comments