This commit is contained in:
kehaoyuan
2019-09-30 18:33:14 +08:00
parent 770543fea5
commit 322f4fd268
16 changed files with 275 additions and 246 deletions

View File

@ -21,7 +21,6 @@ import androidx.core.content.ContextCompat;
public class ExpendTextView extends AppCompatTextView {
private CharSequence mSnapshotText;
private CharSequence mCloseText;
private String mExpendText = "...全文";
@ -48,7 +47,6 @@ public class ExpendTextView extends AppCompatTextView {
super.onLayout(changed, left, top, right, bottom);
if (mInitLayout && !mOpenLayout && getLineCount() > mMaxLines) {
mSnapshotText = getText();
mCloseText = getText();
mInitLayout = false;
showExpendButton();
}
@ -81,7 +79,7 @@ public class ExpendTextView extends AppCompatTextView {
float expendTextWidth = paint.measureText(mExpendText);
CharSequence content = mSnapshotText.subSequence(start, lastLineEnd);
if (viewWidth - lastLineRight > expendTextWidth) {
content = content.toString().trim() + mExpendText;
content = content.toString().trim() + mExpendText ;
} else {
CharSequence lastText = mSnapshotText.subSequence(lastLineStart, lastLineEnd);
for (int i = lastText.length() - 1; i > 0; i--) {
@ -93,7 +91,7 @@ public class ExpendTextView extends AppCompatTextView {
}
}
}
SpannableStringBuilder msp = new SpannableStringBuilder(mCloseText);
SpannableStringBuilder msp = new SpannableStringBuilder(mSnapshotText);
int length = msp.length();
int startPosition = content.length() - mExpendText.length();
startPosition = startPosition < 0 ? 0 : startPosition;