本文整理匯總了Java中android.graphics.Canvas.drawText方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.drawText方法的具體用法?Java Canvas.drawText怎麽用?Java Canvas.drawText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(marksPath, marksPaint);
canvas.drawPath(axisPath, axisPaint);
if (data != null) {
canvas.drawPath(sw1dPath, sw1dPaint);
canvas.drawPath(sw7dPath, sw7dPaint);
canvas.drawPath(sw30dPath, sw30dPaint);
canvas.drawPath(bu1dPath, bu1dPaint);
canvas.drawPath(bu7dPath, bu7dPaint);
canvas.drawPath(bu30dPath, bu30dPaint);
}
// y-labels
for (int i = 4; i >= 0; i--) {
canvas.drawText(String.format(Locale.getDefault(), "%d%%", i * 25), labelWidth, labelHeight + (1.5f * labelHeight + chartHeight) - (i + 1) * (1.5f * labelHeight + chartHeight) / 5, yLabelTextPaint);
}
}
示例2: drawScale
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawScale(Canvas canvas) {
int width = canvas.getWidth();
int height = canvas.getHeight();
float start = (getScrollY() - mDrawOffset) / mParent.getInterval() + mParent.getMinScale();
float end = (getScrollY() + height + mDrawOffset) / mParent.getInterval() + mParent.getMinScale();
for (float i = start; i <= end; i++){
float locationY = (i - mParent.getMinScale()) * mParent.getInterval();
if (i >= mParent.getMinScale() && i <= mParent.getMaxScale()) {
if (i % mCount == 0) {
canvas.drawLine(width - mParent.getBigScaleLength(), locationY, width, locationY, mBigScalePaint);
canvas.drawText(RulerStringUtil.resultValueOf(i,mParent.getFactor()),width - mParent.getTextMarginHead(), locationY + mParent.getTextSize() / 2, mTextPaint);
} else {
canvas.drawLine(width - mParent.getSmallScaleLength(), locationY, width, locationY, mSmallScalePaint);
}
}
}
//畫輪廓線
canvas.drawLine(canvas.getWidth(), getScrollY(), canvas.getWidth(), getScrollY() + height, mOutLinePaint);
}
示例3: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Draws the barcode annotations for position, size, and raw value on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Barcode barcode = mBarcode;
if (barcode == null) {
return;
}
// Draws the bounding box around the barcode.
RectF rect = new RectF(barcode.getBoundingBox());
rect.left = translateX(rect.left);
rect.top = translateY(rect.top);
rect.right = translateX(rect.right);
rect.bottom = translateY(rect.bottom);
canvas.drawRect(rect, mRectPaint);
// Draws a label at the bottom of the barcode indicate the barcode value that was detected.
canvas.drawText(barcode.rawValue, rect.left, rect.bottom, mTextPaint);
}
示例4: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPath.reset();
//貝塞爾曲線
mPath.moveTo(mStartXPoint, mStartYPoint);
mPath.quadTo(mConXPoint, mConYPoint, mEndXPoint, mEndYPoint);
canvas.drawPath(mPath, mPaint);
//輔助線
canvas.drawLine(mStartXPoint, mStartYPoint, mConXPoint, mConYPoint, mLinePaint);
canvas.drawLine(mConXPoint, mConYPoint, mEndXPoint, mEndYPoint, mLinePaint);
//文字
canvas.drawPoint(mStartXPoint, mStartYPoint, mPaint);
canvas.drawText("起始點", mStartXPoint, mStartYPoint + 30, mTextPaint);
canvas.drawPoint(mEndXPoint, mEndYPoint, mPaint);
canvas.drawText("結束點", mEndXPoint, mEndYPoint + 30, mTextPaint);
canvas.drawPoint(mConXPoint, mConYPoint, mPaint);
canvas.drawText("控製點", mConXPoint, mConYPoint - 30, mTextPaint);
}
示例5: onDrawWeekDayLetters
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Invoked to draw first letters of days in week from the specified <var>top</var> position.
* <p>
* Default implementation draws day letters in one row on the specified <var>canvas</var>.
*
* @param canvas The canvas on which to draw day letters.
* @param top Top position from which to start the drawing. This is the position returned from
* {@link #onDrawTitle(Canvas, float, Paint)} method {@code +} {@link #getDayLettersOffsetVertical()}.
* @param paint Paint for day letters ready to be used for drawing.
* @return Updated top position from which following graphic components (day numbers) of this view
* will be drawn.
* @see #onDrawDayNumbers(Canvas, float, Paint)
*/
protected float onDrawWeekDayLetters(@NonNull Canvas canvas, float top, @NonNull Paint paint) {
/**
* We will draw 7 columns for each day in week.
*/
int dayIndex = mFirstDayOfWeek - 1;
paint.getTextBounds(Integer.toString(MAX_DAY_IN_MONTH), 0, 2, TEXT_BOUNDS);
float left = getPaddingLeft() + TEXT_BOUNDS.width() / 2f;
top += (int) paint.getTextSize();
for (int i = 0; i < DAYS_IN_WEEK; i++) {
final String dayLetter = DAY_LETTERS[dayIndex];
canvas.drawText(dayLetter, 0, 1, left, top, paint);
left += mSpacingHorizontal;
if (++dayIndex >= DAYS_IN_WEEK) {
dayIndex = 0;
}
}
return top;
}
示例6: drawData
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawData(Canvas canvas) {
// 先繪製選中的text再往上往下繪製其餘的text
float scale = parabola(mViewHeight / 4.0f, mMoveLen);
float size = (mMaxTextSize - mMinTextSize) * scale + mMinTextSize;
mPaint.setTextSize(size);
mPaint.setAlpha((int) ((mMaxTextAlpha - mMinTextAlpha) * scale + mMinTextAlpha));
// text居中繪製,注意baseline的計算才能達到居中,y值是text中心坐標
float x = (float) (mViewWidth / 2.0);
float y = (float) (mViewHeight / 2.0 + mMoveLen);
FontMetricsInt fmi = mPaint.getFontMetricsInt();
float baseline = (float) (y - (fmi.bottom / 2.0 + fmi.top / 2.0));
if (null != mItemProvider) {
String itemData = mItemProvider.getItem(mDataList.get(mCurrentSelected), mCurrentSelected);
canvas.drawText(itemData, x, baseline, mPaint);
}
// 繪製上方data
for (int i = 1; (mCurrentSelected - i) >= 0; i++) {
drawOtherText(canvas, i, -1);
}
// 繪製下方data
for (int i = 1; (mCurrentSelected + i) < mDataList.size(); i++) {
drawOtherText(canvas, i, 1);
}
}
示例7: onDrawText
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
float baselineY = mTextBaseLine + y;
int cx = x + mItemWidth / 2;
if (hasScheme) {
canvas.drawText(String.valueOf(calendar.getDay()),
cx,
baselineY,
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
} else {
canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
}
}
示例8: drawString
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Draw a multiple lines string.
*
* @param canvas the canvas to paint to
* @param text the text to be painted
* @param x the x value of the area to draw to
* @param y the y value of the area to draw to
* @param paint the paint to be used for drawing
*/
protected void drawString(Canvas canvas, String text, float x, float y, Paint paint) {
if (text != null) {
String[] lines = text.split("\n");
Rect rect = new Rect();
int yOff = 0;
for (int i = 0; i < lines.length; ++i) {
canvas.drawText(lines[i], x, y + yOff, paint);
paint.getTextBounds(lines[i], 0, lines[i].length(), rect);
yOff = yOff + rect.height() + 5; // space between lines is 5
}
}
}
示例9: getWeatherIcon
import android.graphics.Canvas; //導入方法依賴的package包/類
protected Bitmap getWeatherIcon(String text, Context context) {
Bitmap myBitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(context.getAssets(), "fonts/weather.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(150);
paint.setTextAlign(Paint.Align.CENTER);
myCanvas.drawText(text, 128, 180, paint);
return myBitmap;
}
示例10: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 重寫這個方法
*/
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 獲取焦點改變背景顏色.
int height = getHeight();// 獲取對應高度
int width = getWidth(); // 獲取對應寬度
int singleHeight = height / b.length;// 獲取每一個字母的高度
for (int i = 0; i < b.length; i++) {
paint.setColor(getResources().getColor(R.color.rp_text_grey));
paint.setColor(Color.BLACK);
paint.setTypeface(Typeface.DEFAULT);
paint.setAntiAlias(true);
paint.setTextSize(dip2px(mContext, 12));
// 選中的狀態
if (i == choose) {
paint.setColor(getResources().getColor(R.color.rp_primary_dark));
paint.setFakeBoldText(true);
}
// x坐標等於中間-字符串寬度的一半.
float xPos = width / 2 - paint.measureText(b[i]) / 2;
float yPos = singleHeight * i + singleHeight;
canvas.drawText(b[i], xPos, yPos, paint);
paint.reset();// 重置畫筆
}
}
示例11: drawCircle
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawCircle(Canvas canvas, int drawStep, String text, int dx) {
this.mPaint.setColor(this.mStep == drawStep ? mUnderwayCircleColor : this.mStep > drawStep ? mStartedCircleColor : mPreCircleColor);
this.mPaint.setStyle(Paint.Style.STROKE);
this.mPaint.setStrokeWidth(2.0F);
canvas.drawCircle(dx, getHeight() - this.mRadius - 1, this.mRadius, this.mPaint);
this.mPaint.setStyle(Paint.Style.FILL);
canvas.drawCircle(dx, getHeight() - this.mRadius - 1, this.mRadius - 5, this.mPaint);
this.mPaint.setColor(this.mStep == drawStep ? mUnderwayStringColor : this.mStep > drawStep ? mStartedStringColor : mPreStringColor);
this.mPaint.setTextSize(this.mTextSize);
canvas.drawText(text, dx - getWordCount(text) * this.mTextSize, getHeight() - this.mRadius * 2 - 15, this.mPaint);
}
示例12: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void draw(Canvas canvas, Rect bounds) {
int saveCount = canvas.save();
RectF arcBounds = mCurrentBounds;
arcBounds.set(bounds);
//draw bottle
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(mBottleColor);
canvas.drawPath(createBottlePath(mBottleBounds), mPaint);
//draw water
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(mWaterColor);
canvas.drawPath(createWaterPath(mWaterBounds, mProgress), mPaint);
//draw water drop
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mWaterColor);
for (WaterDropHolder waterDropHolder : mWaterDropHolders) {
if (waterDropHolder.mNeedDraw) {
canvas.drawCircle(waterDropHolder.mInitX, waterDropHolder.mCurrentY, waterDropHolder.mRadius, mPaint);
}
}
//draw loading text
mPaint.setColor(mBottleColor);
canvas.drawText(LOADING_TEXT, mBottleBounds.centerX() - mLoadingBounds.width() / 2.0f,
mBottleBounds.bottom + mBottleBounds.height() * 0.2f, mPaint);
canvas.restoreToCount(saveCount);
}
示例13: drawIndex
import android.graphics.Canvas; //導入方法依賴的package包/類
protected void drawIndex(Canvas canvas, int height, float x, int index) {
String text = index + "";
int textHeight = getTextHeight(text, mTextPaint);
float textWidth = getTextWidth(text, mTextPaint);
x -= textWidth / 2.0f;
float y = height - textHeight;
canvas.drawText(text, x, y, mTextPaint);
}
示例14: drawMonthTitle
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 繪製頭部(年份月份,星期幾)
*
* @param canvas
*/
private void drawMonthTitle(Canvas canvas) {
int x = (mWidth + 2 * mPadding) / 2;
int y = (MONTH_HEADER_SIZE - WEEK_TEXT_SIZE) / 2 + (YEAR_MONTH_TEXT_SIZE / 3);
StringBuilder stringBuilder = new StringBuilder(getMonthAndYearString().toLowerCase());
stringBuilder.setCharAt(0, Character.toUpperCase(stringBuilder.charAt(0)));
canvas.drawText(stringBuilder.toString(), x, y, mYearMonthPaint);
}
示例15: addTextWatermark
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 添加文字水印
*
* @param src 源圖片
* @param content 水印文本
* @param textSize 水印字體大小
* @param color 水印字體顏色
* @param x 起始坐標x
* @param y 起始坐標y
* @param recycle 是否回收
* @return 帶有文字水印的圖片
*/
public static Bitmap addTextWatermark(Bitmap src, String content, float textSize, int color, float x,
float y, boolean recycle) {
if (isEmptyBitmap(src) || content == null) return null;
Bitmap ret = src.copy(src.getConfig(), true);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Canvas canvas = new Canvas(ret);
paint.setColor(color);
paint.setTextSize(textSize);
Rect bounds = new Rect();
paint.getTextBounds(content, 0, content.length(), bounds);
canvas.drawText(content, x, y + textSize, paint);
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}