public class MultilineTextView extends TextView {

private boolean calculatedLines = false;

public MultilineTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected void onDraw(Canvas canvas) {
if (!calculatedLines) {
calculateLines();
calculatedLines = true;
}

super.onDraw(canvas);
}

private void calculateLines() {
int mHeight = getMeasuredHeight();
int lHeight = getLineHeight();
int lines = mHeight / lHeight;
setLines(lines);
}
}

posted on 2015-12-14 18:10  Snow〃冰激凌  阅读(2801)  评论(0编辑  收藏  举报