本文整理汇总了Java中android.graphics.Canvas.drawRect方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawRect方法的具体用法?Java Canvas.drawRect怎么用?Java Canvas.drawRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawLabelTextAndBackground
import android.graphics.Canvas; //导入方法依赖的package包/类
protected void drawLabelTextAndBackground(Canvas canvas, char[] labelBuffer, int startIndex, int numChars, int autoBackgroundColor) {
float textX;
float textY;
if (this.isValueLabelBackgroundEnabled) {
if (this.isValueLabelBackgroundAuto) {
this.labelBackgroundPaint.setColor(autoBackgroundColor);
}
canvas.drawRect(this.labelBackgroundRect, this.labelBackgroundPaint);
textX = this.labelBackgroundRect.left + ((float) this.labelMargin);
textY = this.labelBackgroundRect.bottom - ((float) this.labelMargin);
} else {
textX = this.labelBackgroundRect.left;
textY = this.labelBackgroundRect.bottom;
}
if (labelBuffer[startIndex] != '0') {
canvas.drawText(labelBuffer, startIndex, numChars, textX, textY, this.labelPaint);
}
}
示例2: renderNoPage
import android.graphics.Canvas; //导入方法依赖的package包/类
private void renderNoPage(Bitmap bitmap, final RenderListener listener, Rect localVisRect, Rect globalVisRect)
{
// specify where to draw to and from
mDrawBitmap = bitmap;
mDrawSrcRect.set(globalVisRect);
mDrawDstRect.set(localVisRect);
// make a rect representing the entire page in screen coordinates
int[] locations = new int[2];
getLocationOnScreen(locations);
Rect pageRect = new Rect(locations[0], locations[1], locations[0] + getWidth(), locations[1] + getHeight());
// draw a yellow page with a red border containing the page number
Paint p = new Paint();
Canvas c = new Canvas(bitmap);
p.setColor(Color.RED);
p.setStyle(Paint.Style.FILL);
c.drawRect(pageRect, p);
Rect smaller = new Rect(pageRect);
int inset = (int) (40 * mScale);
smaller.inset(inset, inset);
p.setColor(Color.YELLOW);
p.setStyle(Paint.Style.FILL);
c.drawRect(smaller, p);
String s = "" + (mPageNum + 1);
p.setColor(Color.BLACK);
p.setTextSize(200.0f * mScale);
c.drawText(s, pageRect.left + (90 * mScale), pageRect.top + (290 * mScale), p);
invalidate();
listener.progress(0);
}
示例3: drawBar
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void drawBar(Canvas barCanvas) {
int width = barCanvas.getWidth();
int height = barCanvas.getHeight();
barCanvas.drawRect(0, 0, width, height, alphaPatternPaint);
int l = Math.max(2, width / 256);
for (int x = 0; x <= width; x += l) {
float alpha = (float) x / (width - 1);
barPaint.setColor(color);
barPaint.setAlpha(Math.round(alpha * 255));
barCanvas.drawRect(x, 0, x + l, height, barPaint);
}
}
示例4: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Paint paint) {
float rWidth=getWidth()/5;
float rHeight=getHeight()/5;
for (int i = 0; i < 2; i++) {
canvas.save();
canvas.translate(translateX[i], translateY[i]);
canvas.rotate(degrees);
canvas.scale(scaleFloat,scaleFloat);
RectF rectF=new RectF(-rWidth/2,-rHeight/2,rWidth/2,rHeight/2);
canvas.drawRect(rectF,paint);
canvas.restore();
}
}
示例5: drawOtherTopLeftRoundRect
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
paint);
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
}
示例6: scaleTest02
import android.graphics.Canvas; //导入方法依赖的package包/类
private void scaleTest02(Canvas canvas) {
canvas.translate(mWidth / 2, mHeight / 2);
paint.setColor(Color.RED);
Rect rect = new Rect(0, -400, 400, 0);
canvas.drawRect(rect, paint);
canvas.save();
canvas.scale(0.5f, 0.5f, 200, 0);
paint.setColor(Color.BLUE);
canvas.drawRect(rect, paint);
canvas.restore();
}
示例7: drawLayerBounds
import android.graphics.Canvas; //导入方法依赖的package包/类
private static void drawLayerBounds(@Nonnull Canvas canvas,
@Nonnull Rect bounds,
int sectionNumber,
@Nonnull Paint fillPaint,
@Nonnull Paint outlinePaint,
@Nonnull Paint textPaint) {
Rect startRect = new Rect(bounds.left + 1, bounds.top + 1, bounds.right - 1, bounds.bottom - 1);
canvas.drawRect(startRect, fillPaint);
canvas.drawRect(startRect, outlinePaint);
canvas.drawText("" + sectionNumber, bounds.left + 6, bounds.top + 21, textPaint);
}
示例8: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = this.getWidth();
int height = this.getHeight();
double barHeight = 0.0;
if(mPercent > 0){
barHeight = mPercent / 100 * height;
}
mPaint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
canvas.drawRect(0, height-(float)barHeight, width, height, mPaint);
}
示例9: drawVertical
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawVertical(Canvas c, RecyclerView parent) {
int left = parent.getPaddingLeft();
int right = parent.getWidth() - parent.getPaddingRight();
int childCount = parent.getChildCount();
int top, bottom;
View child = null;
RecyclerView.LayoutParams params = null;
for (int i = 0; i < childCount; i++) {
child = parent.getChildAt(i);
params = (RecyclerView.LayoutParams) child.getLayoutParams();
if (i == 0) {
//如果是第一个元素,就绘制上边线
//child.getTop() - params.topMargin 得到的是child的y起点坐标,需要在该y坐标之前绘制宽度为mWidth的线,所以需要减mWidth
top = child.getTop() - params.topMargin - mWidthPx;
bottom = top + mWidthPx;
//绘制上边线
c.drawRect(left, top, right, bottom, mPaint);
}
top = child.getBottom() + params.bottomMargin;
bottom = top + mWidthPx;
c.drawRect(left, top, right, bottom, mPaint);
}
}
示例10: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
if (emojiBmp[info.page][info.page2] == null) {
if (loadingEmoji[info.page][info.page2]) {
return;
}
loadingEmoji[info.page][info.page2] = true;
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public void run() {
loadEmoji(info.page, info.page2);
loadingEmoji[info.page][info.page2] = false;
}
});
canvas.drawRect(getBounds(), placeholderPaint);
return;
}
Rect b;
if (fullSize) {
b = getDrawRect();
} else {
b = getBounds();
}
//if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) {
canvas.drawBitmap(emojiBmp[info.page][info.page2], info.rect, b, paint);
//}
}
示例11: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (mShape == SHAPE_RECT) {
mPaint.setColor(mBgColor);
canvas.drawRect(mBackRect, mPaint);
mPaint.setAlpha(mAlpha);
canvas.drawRect(mBackRect, mPaint);
mFrontRect.set(mFrontRectLeft, RIM_SIZE, mFrontRectLeft
+ getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight()
- RIM_SIZE);
mPaint.setColor(mFgColor);
canvas.drawRect(mFrontRect, mPaint);
if (mClippableView != null) {
ViewCompat.setClipBounds(mClippableView, mFrontRect);
}
} else {
// draw circle
int radius;
radius = mBackRect.height() / 2 - RIM_SIZE;
mPaint.setColor(mBgColor);
mBackCircleRect.set(mBackRect);
canvas.drawRoundRect(mBackCircleRect, radius, radius, mPaint);
mPaint.setColor(mFgColor);
mPaint.setAlpha(mAlpha);
canvas.drawRoundRect(mBackCircleRect, radius, radius, mPaint);
mFrontRect.set(mFrontRectLeft, RIM_SIZE, mFrontRectLeft
+ mBackRect.height() - 2 * RIM_SIZE, mBackRect.height()
- RIM_SIZE);
mFrontCircleRect.set(mFrontRect);
mPaint.setColor(Color.WHITE);
canvas.drawRoundRect(mFrontCircleRect, radius, radius, mPaint);
}
}
示例12: drawUnderline
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawUnderline(Canvas canvas, int left, int right, int height) {
if (bottomBorderThickness <= 0) {
return;
}
// Thin underline along the entire bottom edge
borderPaint.setColor(bottomBorderColor);
canvas.drawRect(left, height - bottomBorderThickness, right, height, borderPaint);
}
示例13: addReflection
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 添加倒影
*
* @param src 源图片的
* @param reflectionHeight 倒影高度
* @param recycle 是否回收
* @return 带倒影图片
*/
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
if (isEmptyBitmap(src)) return null;
// 原图与倒影之间的间距
final int REFLECTION_GAP = 0;
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
srcWidth, reflectionHeight, matrix, false);
Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
Canvas canvas = new Canvas(ret);
canvas.drawBitmap(src, 0, 0, null);
canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
Paint paint = new Paint();
paint.setAntiAlias(true);
LinearGradient shader = new LinearGradient(0, srcHeight,
0, ret.getHeight() + REFLECTION_GAP,
0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawRect(0, srcHeight + REFLECTION_GAP,
srcWidth, ret.getHeight(), paint);
if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}
示例14: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode() || tabCount == 0) {
return;
}
final int height = getHeight();
// draw indicator line
rectPaint.setColor(indicatorColor);
// default: line below current tab
View currentTab = tabsContainer.getChildAt(currentPosition);
float textViewContentWidth = getTextViewContentWidth((TextView) currentTab);
int indicatorSpac = (int) ((TextView) currentTab).getWidth();
float lineLeft = currentTab.getLeft();
float lineRight = currentTab.getRight();
// if there is an offset, start interpolating left and right coordinates
// between current and next tab
if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
View nextTab = tabsContainer.getChildAt(currentPosition + 1);
textViewContentWidth = getTextViewContentWidth((TextView) currentTab);
indicatorSpac = (int) ((TextView) currentTab).getWidth();
final float nextTabLeft = nextTab.getLeft();
final float nextTabRight = nextTab.getRight();
lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset)
* lineLeft);
lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset)
* lineRight);
}
if (indicatorWrapContent) {
canvas.drawRect(lineLeft - wrapAddWidth+getPaddingLeft()
+ (indicatorSpac - textViewContentWidth) / 2, height
- indicatorHeight,
lineRight+getPaddingLeft() - (indicatorSpac - textViewContentWidth) / 2
+ wrapAddWidth, height, rectPaint);
} else {
canvas.drawRect(lineLeft+getPaddingLeft(), height - indicatorHeight, lineRight+getPaddingLeft(),
height, rectPaint);
}
// draw underline
rectPaint.setColor(underlineColor);
canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(),
height, rectPaint);
// draw divider
dividerPaint.setColor(dividerColor);
for (int i = 0; i < tabCount - 1; i++) {
View tab = tabsContainer.getChildAt(i);
canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(),
height - dividerPadding, dividerPaint);
}
}
示例15: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isInEditMode() || tabCount == 0) {
return;
}
final int height = getHeight();
// draw indicator line
rectPaint.setColor(indicatorColor);
// default: line below current tab
View currentTab = tabsContainer.getChildAt(currentPosition);
float lineLeft = currentTab.getLeft();
float lineRight = currentTab.getRight();
// if there is an offset, start interpolating left and right coordinates between current and next tab
if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
View nextTab = tabsContainer.getChildAt(currentPosition + 1);
final float nextTabLeft = nextTab.getLeft();
final float nextTabRight = nextTab.getRight();
lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
}
canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
// draw underline
rectPaint.setColor(underlineColor);
canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
// draw divider
dividerPaint.setColor(dividerColor);
for (int i = 0; i < tabCount - 1; i++) {
View tab = tabsContainer.getChildAt(i);
canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
}
}