@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if(paint==null){
Log.d(TAG, "onMeasure: paint 初始化错误");
return;
}
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int height = MeasureSpec.getSize(widthMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
if(widthMode == MeasureSpec.AT_MOST){
Rect bounds = new Rect();
paint.getTextBounds(my_text,0,my_text.length(),bounds);
width = bounds.width() + getPaddingLeft() +getPaddingRight();
}
if(heightMode == MeasureSpec.AT_MOST){
Rect bounds = new Rect();
paint.getTextBounds(my_text,0,my_text.length(),bounds);
height = bounds.height() + getPaddingTop() +getPaddingBottom();
}
setMeasuredDimension(width,height);
}
文本显示时,显示的内容只有基线以上的信息,基线以下不显示,比如y显示为v。但是看网友的代码高度都是bound.height(),直接加数值可以显示全部,但就不是自适应了,所以不知道怎么改