当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.drawText方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:lambdasoup,项目名称:blockvote,代码行数:20,代码来源:HistoryView.java

示例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);
}
 
开发者ID:totond,项目名称:BooheeRuler,代码行数:21,代码来源:RightHeadRuler.java

示例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);
}
 
开发者ID:ravi8x,项目名称:Barcode-Reader,代码行数:22,代码来源:BarcodeGraphic.java

示例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);

}
 
开发者ID:Lichenwei-Dev,项目名称:BezierView,代码行数:23,代码来源:BezierQuadView.java

示例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;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:32,代码来源:MonthView.java

示例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);
    }
}
 
开发者ID:yhyzgn,项目名称:Widgets,代码行数:26,代码来源:PickerView.java

示例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);
    }
}
 
开发者ID:yhyonghao,项目名称:CalendarView_master,代码行数:18,代码来源:SimpleCalendarCardView.java

示例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
    }
  }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:22,代码来源:AbstractChart.java

示例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;
}
 
开发者ID:hichemcesar24,项目名称:Weather-Android,代码行数:16,代码来源:AbstractWidgetProvider.java

示例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();// 重置画笔
    }

}
 
开发者ID:YunzhanghuOpen,项目名称:redpacketui-open,代码行数:30,代码来源:RPSideBar.java

示例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);
}
 
开发者ID:WrBug,项目名称:timelineview,代码行数:12,代码来源:TimeLineView.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:WaterBottleLoadingRenderer.java

示例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);
}
 
开发者ID:littleGnAl,项目名称:ScrollableChart,代码行数:9,代码来源:DemoDrawing.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:SimpleMonthView.java

示例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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:ImageUtils.java


注:本文中的android.graphics.Canvas.drawText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。