本文整理匯總了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);
}