本文整理匯總了Java中android.graphics.Canvas.getHeight方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.getHeight方法的具體用法?Java Canvas.getHeight怎麽用?Java Canvas.getHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.getHeight方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Draws the overlay with its associated graphic objects.
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
synchronized (mLock) {
if ((mPreviewWidth != 0) && (mPreviewHeight != 0)) {
mWidthScaleFactor = (float) canvas.getWidth() / (float) mPreviewWidth;
mHeightScaleFactor = (float) canvas.getHeight() / (float) mPreviewHeight;
}
for (Graphic graphic : mGraphics) {
graphic.draw(canvas);
}
}
}
示例2: doDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void doDraw(Canvas canvas) {
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
if (canvasWidth != this.mContainerWidth || canvasHeight != this.mContainerHeight) {//phone rotated !
this.mContainerWidth = canvasWidth;
this.mContainerHeight = canvasHeight;
}
canvas.save();
canvas.translate(mCurrX,mCurrY);
// for (int i = 0; i < 4; i++) { //加深陰影,產生描邊效果. stroke/outline effect
// staticLayout.draw(canvas);
// }
borderStaticLayout.draw(canvas);
staticLayout.draw(canvas);
canvas.restore();
mCurrX = (int) (mCurrX - sBaseSpeed * mFactor);//only support moving along X axis
}
示例3: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
int layerId = canvas.saveLayer(0, 0, canvasWidth, canvasHeight, null, Canvas.ALL_SAVE_FLAG);
{
bgPaint.setColor(bgColor);
// draw the background of progress
canvas.drawRoundRect(bgRect, rectRadius, rectRadius, bgPaint);
// draw progress
canvas.drawRect(progressRect, progressPaint);
bgPaint.setXfermode(null);
if (bitmap != null) {
//draw icon
canvas.drawBitmap(bitmap, srcRect, dstRect, bgPaint);
}
}
canvas.restoreToCount(layerId);
// TODO: 弄明白為什麽在xml預覽中,canvas.restoreToCount
// TODO: 會導致後續的canvas對象為空 但canvas.restore方法則不會導致這個問題
// canvas.restore();
// canvas.save();
}
示例4: initDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
private void initDraw(Canvas canvas) {
width = canvas.getWidth();
height = canvas.getHeight();
centerHeight = height >> 1;
//振幅為寬度的1/8
//如果未設置振幅高度,則使用默認高度
if (amplitude == 0) {
amplitude = width >> 3;
}
//初始化采樣點及映射
//這裏因為包括起點和終點,所以需要+1
samplingX = new float[SAMPLING_SIZE + 1];
mapX = new float[SAMPLING_SIZE + 1];
//確定采樣點之間的間距
float gap = width / (float)SAMPLING_SIZE;
//采樣點的位置
float x;
for (int i = 0; i <= SAMPLING_SIZE; i++){
x = i * gap;
samplingX[i] = x;
//將采樣點映射到[-2,2]
mapX[i] = (x / (float)width) * 4 - 2;
}
}
示例5: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas) {
if (isInEditMode()) {
return;
}
Rect frame = mFrameRect;
if (frame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// 繪製焦點框外邊的暗色背景
mPaint.setColor(mMaskColor);
canvas.drawRect(0, 0, width, frame.top, mPaint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, mPaint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, mPaint);
canvas.drawRect(0, frame.bottom + 1, width, height, mPaint);
drawFocusRect(canvas, frame);
drawAngle(canvas, frame);
drawText(canvas, frame);
drawLaser(canvas, frame);
}
示例6: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Draws the overlay with its associated graphic objects.
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
synchronized (mLock) {
if ((mPreviewWidth != 0) && (mPreviewHeight != 0)) {
sWidthScaleFactor = (float) canvas.getWidth() / (float) mPreviewWidth;
sHeightScaleFactor = (float) canvas.getHeight() / (float) mPreviewHeight;
}
for (Graphic graphic : mGraphics) {
graphic.draw(canvas);
}
}
}
示例7: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
if (mOffscreenBitmap == null) {
mOffscreenBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mOffscreenCanvas = new Canvas(mOffscreenBitmap);
BitmapShader mBitmapShader = new BitmapShader(mOffscreenBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setShader(mBitmapShader);
mRectF = new RectF(0f, 0f, canvas.getWidth(), canvas.getHeight());
}
super.draw(mOffscreenCanvas);
canvas.drawRoundRect(mRectF, 16, 16, mPaint);
}
示例8: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas) {
Paint background = new Paint();
background.setColor(Color.WHITE);
background.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawPaint(background);
if (timeSeries == null || timeSeries.isEmpty()) {
return; // No points, so skip.
}
// Calculate bounds for the X axis.
TimeSeriesSnapshot<Double[]> snapshot = timeSeries.getRecentSnapshot(Double[].class);
long timeEndMicro = snapshot.timestamps[snapshot.length - 1];
long timeStartMicro = snapshot.timestamps[0];
double timeDeltaInv = 1.0 / (double)(timeEndMicro - timeStartMicro);
for (int i = 0; i < snapshot.length; i++) {
double x = snapshot.values[i][0]; // Relative Theta
double y = snapshot.values[i][1]; // Relative Beta
float fX = (float)(x * canvas.getWidth());
float fY = (float)((1 - y) * canvas.getHeight());
float fR = DOT_RADIUS * canvas.getWidth();
double age = Math.min(1, Math.max(0,
(timeEndMicro - snapshot.timestamps[i]) * timeDeltaInv));
canvas.drawCircle(fX, fY, fR, paintForAge(age));
}
}
示例9: drawBGRect
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 繪製焦點框外邊的暗色背景
*
* @param canvas
* @param rect
*/
private void drawBGRect(Canvas canvas, Rect rect) {
int width = canvas.getWidth();
int height = canvas.getHeight();
// 畫筆顏色
mPaint.setColor(mMaskColor);
canvas.drawRect(0, 0, width, rect.top, mPaint);
canvas.drawRect(0, rect.top, rect.left, rect.bottom + 1, mPaint);
canvas.drawRect(rect.right + 1, rect.top, width, rect.bottom + 1, mPaint);
canvas.drawRect(0, rect.bottom + 1, width, height, mPaint);
}
示例10: drawPath
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* The graphical representation of a path.
*
* @param canvas the canvas to paint to
* @param points the points that are contained in the path to paint
* @param paint the paint to be used for painting
* @param circular if the path ends with the start point
*/
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular) {
Path path = new Path();
int height = canvas.getHeight();
int width = canvas.getWidth();
float[] tempDrawPoints;
if (points.size() < 4) {
return;
}
tempDrawPoints = calculateDrawPoints(points.get(0), points.get(1), points.get(2),
points.get(3), height, width);
path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
int length = points.size();
for (int i = 4; i < length; i += 2) {
if ((points.get(i - 1) < 0 && points.get(i + 1) < 0)
|| (points.get(i - 1) > height && points.get(i + 1) > height)) {
continue;
}
tempDrawPoints = calculateDrawPoints(points.get(i - 2), points.get(i - 1), points.get(i),
points.get(i + 1), height, width);
if (!circular) {
path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
}
path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
}
if (circular) {
path.lineTo(points.get(0), points.get(1));
}
canvas.drawPath(path, paint);
}
示例11: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
int w = canvas.getWidth(), h = canvas.getHeight();
bgPaint.setColor(bgColor);
fgPaint.setColor(fgColor);
bgRect.set(0, 0, w, h);
fgRect.set(0, 0, (int)(percentage * w), h);
canvas.drawRect(bgRect, bgPaint);
canvas.drawRect(fgRect, fgPaint);
}
示例12: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public final void draw(@NonNull final Canvas canvas) {
int width = canvas.getWidth();
int height = canvas.getHeight();
int intrinsicWidth = background.getIntrinsicWidth();
int intrinsicHeight = background.getIntrinsicHeight();
int left = (width / 2) - (intrinsicWidth / 2);
int top = (height / 2) - (intrinsicHeight / 2);
background.getIntrinsicWidth();
background.setBounds(left, top, left + intrinsicWidth, top + intrinsicHeight);
background.draw(canvas);
float x = width / 2f;
float y = (height / 2f) - ((paint.descent() + paint.ascent()) / 2f);
canvas.drawText(label, x, y, paint);
}
示例13: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
if (middleLine.getColor() != Color.BLUE) {
middleLine.setColor(color);
}
if (bytes != null) {
float barWidth = getWidth() / density;
float div = bytes.length / density;
canvas.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2, middleLine);
paint.setStrokeWidth(barWidth - gap);
for (int i = 0; i < density; i++) {
int x = (int) Math.ceil(i * div);
int top = canvas.getHeight() / 2
+ (128 - Math.abs(bytes[x]))
* (canvas.getHeight() / 2) / 128;
int bottom = canvas.getHeight() / 2
- (128 - Math.abs(bytes[x]))
* (canvas.getHeight() / 2) / 128;
canvas.drawLine(i * barWidth, bottom, i * barWidth, getHeight() / 2, paint);
canvas.drawLine(i * barWidth, top, i * barWidth, getHeight() / 2, paint);
}
super.onDraw(canvas);
}
}
示例14: drawHorizontalPicker
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawHorizontalPicker(Canvas canvas) {
rect.left = 0;
rect.top = 0;
rect.right = 0;
rect.bottom = canvas.getHeight();
// 8%
int margin = Math.round(canvas.getHeight() * 0.08f);
for (int i = 0; i < colors.length; i++) {
paint.setColor(colors[i]);
rect.left = rect.right;
rect.right += cellSize;
if (isColorSelected && colors[i] == selectedColor) {
rect.top = 0;
rect.bottom = canvas.getHeight();
} else {
rect.top = margin;
rect.bottom = canvas.getHeight() - margin;
}
canvas.drawRect(rect, paint);
}
}
示例15: createRoundIconWithText
import android.graphics.Canvas; //導入方法依賴的package包/類
static Bitmap createRoundIconWithText(Context context, String letter) {
//calculate dimensions
//-1 to take into account the shadow layer
int w = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
int h = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
int r = w / 2 - 1;
//create bitmap
Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
//draw a circle of the same dimensions
Canvas canvas = new Canvas(b);
Paint paint = new Paint();
int color = ContextCompat.getColor(context, getRandom(SolidWallpaperUtils.material_colors));
paint.setColor(color);
final int SHADOW_COLOR = 0x80000000;
paint.setShadowLayer(0.5f, 1, 1, SHADOW_COLOR);
paint.setAntiAlias(true);
canvas.drawCircle(r, r, r, paint);
Paint textPaint = new Paint();
textPaint.setColor(Utilities.getComplementaryColor(color));
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setTextSize(w / 2);
textPaint.setAntiAlias(true);
textPaint.setTypeface(Typeface.SANS_SERIF);
int xPos = (canvas.getWidth() / 2);
int yPos = (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2));
canvas.drawText(letter, xPos, yPos, textPaint);
return b;
}