修复 ExpandTextView 尾部空隙太大的问题
This commit is contained in:
@ -12,7 +12,6 @@ import android.text.style.ClickableSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
@ -91,6 +90,7 @@ public class ExpandTextView extends AppCompatTextView {
|
||||
|
||||
private void showExpandButton() {
|
||||
String finalEndText = "";
|
||||
TextPaint paint = getPaint();
|
||||
|
||||
Layout layout = getLayout();
|
||||
int start = layout.getLineStart(0);
|
||||
@ -101,12 +101,10 @@ public class ExpandTextView extends AppCompatTextView {
|
||||
int viewWidth = getWidth() - getPaddingRight() - getPaddingLeft();
|
||||
int additionalEndTextCount = 0;
|
||||
|
||||
TextPaint paint = getPaint();
|
||||
float expandTextWidth;
|
||||
if (mUseGradientAlphaEndText) {
|
||||
additionalEndTextCount = DEFAULT_ADDITIONAL_END_TEXT_COUNT;
|
||||
// 如果不加多个空格的话有可能算不对,惊了,明明是同样的 paint 同样的文字,长度却会略有不同
|
||||
expandTextWidth = paint.measureText(mEndText + mExpandText + " ");
|
||||
expandTextWidth = paint.measureText(mEndText + mExpandText);
|
||||
} else {
|
||||
expandTextWidth = paint.measureText(mExpandText);
|
||||
}
|
||||
@ -128,7 +126,7 @@ public class ExpandTextView extends AppCompatTextView {
|
||||
for (int i = lastText.length() - 1; i > 0; i--) {
|
||||
CharSequence sequence = lastText.subSequence(0, i);
|
||||
float w = paint.measureText(sequence.toString());
|
||||
if (viewWidth - w - DisplayUtils.dip2px(5) > expandTextWidth) {
|
||||
if (viewWidth - w > expandTextWidth) {
|
||||
if (mUseGradientAlphaEndText) {
|
||||
finalEndText = lastText.subSequence(i - additionalEndTextCount, i) + mEndText;
|
||||
finalEndText = finalEndText.replace("\n", "");
|
||||
@ -195,7 +193,8 @@ public class ExpandTextView extends AppCompatTextView {
|
||||
int heightBetweenLastVisibleLineRectAndLastActualLineRect = (mLastActualLineRect.bottom - mLastVisibleLineRect.bottom);
|
||||
|
||||
if (getMeasuredHeight() == getLayout().getHeight() - heightBetweenLastVisibleLineRectAndLastActualLineRect) {
|
||||
result = mLastVisibleLineRect.bottom - (lastVisibleLineBaseline + layout.getPaint().getFontMetricsInt().descent + getPaddingBottom());
|
||||
result = mLastVisibleLineRect.bottom - (lastVisibleLineBaseline + layout.getPaint()
|
||||
.getFontMetricsInt().descent + getPaddingBottom());
|
||||
if (getLineSpacingExtra() > result) {
|
||||
result = 0;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user