}
private void drawTexts(String[] ss, Paint paint, Canvas canvas, int x, int y) {
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
float top = fontMetrics.top;
float bottom = fontMetrics.bottom;
int length = ss.length;
float total = (length - 1) * (bottom - top) + (fontMetrics.descent - fontMetrics.ascent);
float offset = total / 2 - bottom;
for (int i = 0; i < length; i++) {
float yAxis = -(length - i - 1) * (bottom - top) + offset;
canvas.drawText(ss[i], x, y + yAxis + 10, paint);
}
}
/**
-
设置水印文字内容
-
@param text 文字内容
*/
public void setText(String… text) {
mText = text;
textWidth = 0;
textHeight = 0;
if (mText != null && mText.length > 0) {
for (String s : mText) {
Rect tvRect = new Rect();
mTextPaint.getTextBounds(s, 0, s.length(), tvRect);
textWidth = textWidth > tvRect.width() ? textWidth : tvRect.width();
textHeight += (tvRect.height() + 10);
}
}
postInvalidate();
}
/**
-
同步设置水印文字内容
-
@param text 文字内容
*/
void setSyncText(String… text) {
if (mSync) {
setText(text);
}
}
/**
-
设置水印倾斜角度
-
@param degrees 倾斜角度(默认:-30)
*/
public void setDegrees(int degrees) {
mDegrees = degrees;
postInvalidate();
}
/**
-
同步设置水印倾斜角度
-
@param degrees 倾斜角度(默认:-30)
*/
void setSyncDegrees(int degrees) {
if (mSync) {
setDegrees(degrees);
}
}
/**
-
设置水印字体颜色
-
@param textColor 字体颜色(默认:#33000000)
*/
public void setTextColor(int textColor) {
mTextColor = textColor;
mTextPaint.setColor(mTextColor);
postInvalidate();
}
/**
-
同步设置水印字体颜色
-
@param textColor 字体颜色(默认:#33000000)
*/
void setSyncTextColor(int textColor) {
if (mSync) {
setTextColor(textColor);
}
}
/**
-
设置水印字体大小(单位:px)
-
@param textSize 字体大小(默认:42px)
*/
public void setTextSize(int textSize) {
mTextSize = textSize;
mTextPaint.setTextSize(30);
postInvalidate();
}
/**
-
同步设置水印字体大小(单位:px)
-
@param textSize 字体大小(默认:42px)
*/
void setSyncTextSize(int textSize) {
if (mSync) {
setTextSize(30);
}
}
/**
-
<