我是新来的堆栈溢出,所以请不要吝啬
要打开我的可扩展文本视图,我需要双击,但我不知道为什么。请帮帮我。我还注意到如果我删除了“!”在第22行中,我需要点击一次,但它不再收缩。
要打开我的可扩展文本视图,我需要双击,但我不知道为什么。请帮帮我。我还注意到如果我删除了“!”在第22行中,我需要点击一次,但它不再收缩。
class ExpandableTextView extends androidx.appcompat.widget.AppCompatTextView {
private static final int DEFAULT_TRIM_LENGTH = 205;
public final String ELLIPSIS = "show more";
private CharSequence originalText;
private CharSequence trimmedText;
private BufferType bufferType;
private boolean trim = true;
private int trimLength;
public ExpandableTextView(Context context) {
this(context, null);
}
public ExpandableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
this.trimLength = typedArray.getInt(R.styleable.ExpandableTextView_trimLength, DEFAULT_TRIM_LENGTH);
typedArray.recycle();
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
trim = !trim;
setText();
}
});
}
private void setText() {
super.setText(getDisplayableText(), bufferType);
}
private CharSequence getDisplayableText() {
return trim ? originalText : trimmedText;
}
@Override
public void setText(CharSequence text, BufferType type) {
originalText = text;
trimmedText = getTrimmedText(text);
bufferType = type;
setText();
}
private CharSequence getTrimmedText(CharSequence text) {
if (originalText != null && originalText.length() > trimLength) {
return new SpannableStringBuilder(originalText, 0, trimLength + 205).append(ELLIPSIS);
} else {
return originalText;
}
}
public CharSequence getOriginalText() {
return originalText;
}
public void setTrimLength(int trimLength) {
this.trimLength = trimLength;
trimmedText = getTrimmedText(originalText);
setText();
}
public int getTrimLength() {
return trimLength;
}
}
我不知道,请帮忙!
暂无答案!
目前还没有任何答案,快来回答吧!