要实现的效果如图:
实现代码
public class ExpandTextView extends RelativeLayout {
private TextView mText;
private TextView mExpandText;
private int mTextColor = 0xff828282;
private int mTextLine = 1;
private int mStart;
private int mEnd;
private boolean isFirst = true;
private boolean isExpand = false;
public ExpandTextView(Context context) {
this(context, null);
}
public ExpandTextView(Context context, AttributeSet attrs) {
this(context,attrs, 0);
}
public ExpandTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
mText = new TextView(context, attrs);
mText.setTextColor(mTextColor);
mText.setEllipsize(TextUtils.TruncateAt.END);
mText.setMaxLines(mTextLine);
addView(mText, params);
mExpandText = new TextView(context);
mExpandText.setTextColor(mTextColor);
addView(mExpandText, params);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final ViewGroup.LayoutParams params =