本文整理汇总了Java中android.graphics.Canvas.drawLine方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawLine方法的具体用法?Java Canvas.drawLine怎么用?Java Canvas.drawLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDraw(final Canvas canvas) {
super.onDraw(canvas);
final float y = (1.0f - value) * canvas.getHeight();
// If all sliders are zero, don't bother shading anything.
if (!allZero) {
canvas.drawRect(0, 0, canvas.getWidth(), y, boxPaint);
}
if (value > 0.0f) {
canvas.drawLine(0, y, canvas.getWidth(), y, linePaint);
}
if (hilighted) {
canvas.drawRect(0, 0, getWidth(), getHeight(), linePaint);
}
}
示例2: drawStationLine
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 駅軸を描画する
*
*/
private void drawStationLine(Canvas canvas){
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.rgb(200, 200, 200));
for (int i = 0; i < station.getStationNum(); i++) {
if (station.getRouteStation(i).isBigStation()) {
paint.setStrokeWidth(defaultLineSize);
} else {
paint.setStrokeWidth(defaultLineSize*0.5f);
}
canvas.drawLine(0,stationTime.get(i) * scaleY / 60+yshift, 60*24* scaleX,stationTime.get(i) * scaleY / 60+yshift, paint);
}
}
示例3: generateLinearLines
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* generate the linear function lines
* @param a {@link LinearType#LinearType(float, float)}
* @param b {@link LinearType#LinearType(float, float)}
* @param canvas canvas
*/
private void generateLinearLines(Float a, Float b, Canvas canvas) {
// raw
PointF start = leftPoint;
PointF end = rightPoint;
// logical
PointF startLogic = convertRawPoint2Logical(start, unitLength);
PointF endLogic = convertRawPoint2Logical(end, unitLength);
// calculate
startLogic.y = FuncUtils.getLinearYValue(a, b, startLogic.x);
endLogic.y = FuncUtils.getLinearYValue(a, b, endLogic.x);
// convert logical to raw
PointF startRaw = convertLogicalPoint2Raw(startLogic, unitLength);
PointF endRaw = convertLogicalPoint2Raw(endLogic, unitLength);
// draw lines
canvas.drawLine(startRaw.x, startRaw.y, endRaw.x, endRaw.y, functionLinePaint);
}
示例4: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 作用:绘制分割线
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setColor(color);
setTextColor(color);
// 绘制分割线
// 需要考虑:当输入长度超过输入框时,所画的线需要跟随着延伸
// 解决方案:线的长度 = 控件长度 + 延伸后的长度
int x=this.getScrollX(); // 获取延伸后的长度
int w=this.getMeasuredWidth(); // 获取控件长度
// 传入参数时,线的长度 = 控件长度 + 延伸后的长度
canvas.drawLine(0, this.getMeasuredHeight()- linePosition, w+x,
this.getMeasuredHeight() - linePosition, mPaint);
}
示例5: drawLine
import android.graphics.Canvas; //导入方法依赖的package包/类
private static void drawLine(Canvas canvas, Paint paint, ResultPoint a,
ResultPoint b, float scaleFactor) {
if (a != null && b != null) {
canvas.drawLine(scaleFactor * a.getX(), scaleFactor * a.getY(),
scaleFactor * b.getX(), scaleFactor * b.getY(), paint);
}
}
示例6: drawLine
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawLine(Canvas canvas, int canvasWidth, float startX, float startY, float stopX, float stopY, int currentIndexColor) {
mPaint.setColor(mColors[currentIndexColor]);
if (!mMirrorMode) {
canvas.drawLine(startX, startY, stopX, stopY, mPaint);
} else {
if (mReversed) {
canvas.drawLine(canvasWidth + startX, startY, canvasWidth + stopX, stopY, mPaint);
canvas.drawLine(canvasWidth - startX, startY, canvasWidth - stopX, stopY, mPaint);
} else {
canvas.drawLine(startX, startY, stopX, stopY, mPaint);
canvas.drawLine(canvasWidth * 2 - startX, startY, canvasWidth * 2 - stopX, stopY, mPaint);
}
}
}
示例7: drawAllXLine
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 画所有横向表格,包括X轴
*/
private void drawAllXLine(Canvas canvas) {
for (int i = 0; i < spacingHeight + 1; i++) {
canvas.drawLine(blwidh, bheight - (bheight / spacingHeight) * i + marginTop, (canvasWidth - blwidh),
bheight - (bheight / spacingHeight) * i + marginTop, mPaint);// Y坐标
drawText(String.valueOf(averageValue * i), blwidh / 2, bheight - (bheight / spacingHeight) * i + marginTop,
canvas);
}
}
示例8: drawRay
import android.graphics.Canvas; //导入方法依赖的package包/类
void drawRay(Canvas g, float x1, float y1, float x2, float y2, boolean forceRay) {
boolean r = forceRay;
if (!r) {
r = (x1 < lens.x || x2 < lens.x);
if (state == Reflection.CONVERGING_LENS
|| state == Reflection.DIVERGING_LENS)
r = !r;
}
Paint p = r ? ray : rayContinuation;
g.drawLine(x1, y1, x2, y2, p);
}
示例9: drawBarGraph
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawBarGraph(Canvas canvas) {
if (mData == null) return;
for (int i = 0; i < mData.length; i++) {
int x = (int) getXFromIndex(i);
canvas.drawLine(x, getYFromValue(mData[i]), x, getHeight(), mPaintLine);
}
}
示例10: drawGuidesLine
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 绘制辅助线
*
* @param viewSize 视图边长
* @param canvas 画布
*/
public final void drawGuidesLine(int viewSize, Canvas canvas) {
canvas.drawLine(0, 0, viewSize, 0, mNormalPaint);
canvas.drawLine(0, viewSize / 3, viewSize, viewSize / 3, mNormalPaint);
canvas.drawLine(0, 2 * viewSize / 3, viewSize, 2 * viewSize / 3, mNormalPaint);
canvas.drawLine(0, viewSize - 1, viewSize - 1, viewSize - 1, mNormalPaint);
canvas.drawLine(0, 0, 0, viewSize, mNormalPaint);
canvas.drawLine(viewSize / 3, 0, viewSize / 3, viewSize, mNormalPaint);
canvas.drawLine(2 * viewSize / 3, 0, 2 * viewSize / 3, viewSize, mNormalPaint);
canvas.drawLine(viewSize - 1, 0, viewSize - 1, viewSize - 1, mNormalPaint);
}
示例11: renderShape
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {
final float shapeHalf = dataSet.getScatterShapeSize() / 2f;
c.drawLine(
posX - shapeHalf,
posY - shapeHalf,
posX + shapeHalf,
posY + shapeHalf,
renderPaint);
}
示例12: drawContour
import android.graphics.Canvas; //导入方法依赖的package包/类
public static void drawContour(Canvas canvas, List<Point> contour, int color) {
pointPaint.setColor(color);
int len = contour.size();
for (int i = 0; i < len; ++i) {
int next_i = (i + 1) % len;
Point p = contour.get(i), next = contour.get(next_i);
canvas.drawLine(
transformX(p.x), transformY(p.y), transformX(next.x), transformY(next.y),
pointPaint);
}
}
示例13: drawLeftSqrBracket
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawLeftSqrBracket(Canvas c)
{
c.drawLine(rect.centerX(), rect.top, rect.centerX(), rect.bottom, paint);
c.drawLine(rect.centerX(), rect.top, rect.right, rect.top, paint);
c.drawLine(rect.centerX(), rect.bottom, rect.right, rect.bottom, paint);
}
示例14: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
// drawing color wheel
canvas.drawBitmap(colorWheelBitmap, centerX - colorWheelRadius, centerY
- colorWheelRadius, null);
// drawing color view
colorViewPaint.setColor(Color.HSVToColor(colorHSV));
canvas.drawPath(colorViewPath, colorViewPaint);
// drawing value slider
float[] hsv = new float[]{colorHSV[0], colorHSV[1], 1f};
SweepGradient sweepGradient = new SweepGradient(centerX, centerY,
new int[]{Color.BLACK, Color.HSVToColor(hsv), Color.WHITE},
null);
sweepGradient.setLocalMatrix(gradientRotationMatrix);
valueSliderPaint.setShader(sweepGradient);
canvas.drawPath(valueSliderPath, valueSliderPaint);
// drawing color wheel pointer
float hueAngle = (float) Math.toRadians(colorHSV[0]);
int colorPointX = (int) (-Math.cos(hueAngle) * colorHSV[1] * colorWheelRadius)
+ centerX;
int colorPointY = (int) (-Math.sin(hueAngle) * colorHSV[1] * colorWheelRadius)
+ centerY;
float pointerRadius = 0.075f * colorWheelRadius;
int pointerX = (int) (colorPointX - pointerRadius / 2);
int pointerY = (int) (colorPointY - pointerRadius / 2);
colorPointerCoords.set(pointerX, pointerY, pointerX + pointerRadius,
pointerY + pointerRadius);
canvas.drawOval(colorPointerCoords, colorPointerPaint);
// drawing value pointer
valuePointerPaint.setColor(Color.HSVToColor(new float[]{0f, 0f,
1f - colorHSV[2]}));
double valueAngle = (colorHSV[2] - 0.5f) * Math.PI;
float valueAngleX = (float) Math.cos(valueAngle);
float valueAngleY = (float) Math.sin(valueAngle);
canvas.drawLine(valueAngleX * innerWheelRadius + centerX, valueAngleY
* innerWheelRadius + centerY, valueAngleX * outerWheelRadius
+ centerX, valueAngleY * outerWheelRadius + centerY,
valuePointerPaint);
// drawing pointer arrow
if (arrowPointerSize > 0) {
drawPointerArrow(canvas);
}
}
示例15: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@SuppressLint("DrawAllocation")
@Override
public void onDraw(@NonNull Canvas canvas) {
Layout layout = getLayout();
if (layout != null) {
int count = getLineCount();
int scrollY = getScrollY();
mFirst = layout.getLineForVertical(scrollY);
mLast = layout.getLineForVertical(getHeight() + scrollY);
getDrawingRect(mDrawingRect);
mScrollMax.x = 0;
getLineBounds(count - 1, mLineBounds);
mScrollMax.y = Math.max((mLineBounds.bottom + mPadding) - mDrawingRect.height(), 0);
int usableWidth = mDrawingRect.width() - (mLeftPadding + mPadding);
if(HIGHLIGHT_CURRENT_LINE) {
getLineBounds(getLine(), mLineBounds);
canvas.drawRect(mLineBounds, mPaintHighlight);
}
if (SHOW_LINE_NUMBERS) {
updateLinePadding();
int lineX = (int) (mDrawingRect.left + mLeftPadding - (FIXED_TEXT_SIZE * 0.5));
canvas.drawLine(lineX, mDrawingRect.top, lineX, mDrawingRect.bottom, mPaintNumbers);
}
int i = mFirst;
while (i <= mLast) {
int baseline = getLineBounds(i, mLineBounds);
if(SHOW_LINE_NUMBERS) {
canvas.drawText("" + (i + 1), mDrawingRect.left, baseline, mPaintNumbers);
}
int lineWidth = (int) layout.getLineWidth(i);
if (lineWidth > usableWidth) {
mScrollMax.x = Math.max(mScrollMax.x, (lineWidth - usableWidth) + mPadding);
}
i++;
}
if (!(mSizeRedrawInvoked || mOnSizeRedrawListener == null)) {
mSizeRedrawInvoked = true;
mOnSizeRedrawListener.onSizeRedraw();
}
}
super.onDraw(canvas);
}