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


Java Canvas.translate方法代码示例

本文整理汇总了Java中android.graphics.Canvas.translate方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.translate方法的具体用法?Java Canvas.translate怎么用?Java Canvas.translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode()) {
        canvas.drawColor(Color.WHITE);
        canvas.translate(canvas.getWidth() / 2, 30);
        Paint paint = new Paint();
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setTextSize(30);
        paint.setColor(Color.GRAY);
        canvas.drawText("MarkdownView", -30, 0, paint);
    }
}
 
开发者ID:GcsSloop,项目名称:diycode,代码行数:14,代码来源:MarkdownView.java

示例2: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        //super.draw(canvas, text, start, end, x, top, y, bottom, paint);
        Drawable b = getCachedDrawable();
        int count = canvas.save();

//        int transY = fontMetricesBottom - b.getBounds().bottom;
//        int transY -= paint.getFontMetricsInt().descent;

        // 因为 TextView 加了 lineSpacing 之后会导致这里的 bottom、top 参数与单行情况不一样,所以不用 bottom、top,而使用 fontMetrics 的高度来计算
        int fontMetricesTop = y + paint.getFontMetricsInt().top;
        int fontMetricesBottom = fontMetricesTop + (paint.getFontMetricsInt().bottom - paint.getFontMetricsInt().top);
        int transY = fontMetricesTop + ((fontMetricesBottom - fontMetricesTop) / 2) - ((b.getBounds().bottom - b.getBounds().top) / 2) - mTop;

        transY += mTranslateY;

        canvas.translate(x, transY);
        b.draw(canvas);
        canvas.restoreToCount(count);
    }
 
开发者ID:coopese,项目名称:qmui,代码行数:21,代码来源:EmojiconSpan.java

示例3: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {		
	if(!mClockwise) {
		canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY() );
	}
	
	// Draw the arcs
	final int arcStart = mStartAngle + mAngleOffset + mRotation;
	final int arcSweep = mSweepAngle;
	canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
	canvas.drawArc(mArcRect, arcStart, mProgressSweep, false,
			mProgressPaint);

	if(mEnabled) {
		// Draw the thumb nail
		canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
		mThumb.draw(canvas);
	}
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:20,代码来源:SeekArc.java

示例4: drawPacman

import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawPacman(Canvas canvas,Paint paint){
    float x=getWidth()/2;
    float y=getHeight()/2;

    canvas.save();

    canvas.translate(x, y);
    canvas.rotate(degrees1);
    paint.setAlpha(255);
    RectF rectF1=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
    canvas.drawArc(rectF1, 0, 270, true, paint);

    canvas.restore();

    canvas.save();
    canvas.translate(x, y);
    canvas.rotate(degrees2);
    paint.setAlpha(255);
    RectF rectF2=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
    canvas.drawArc(rectF2,90,270,true,paint);
    canvas.restore();
}
 
开发者ID:Mrqinlei,项目名称:ImitateZHRB,代码行数:23,代码来源:PacmanIndicator.java

示例5: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void draw(Canvas canvas, float ms) {
    mPath.reset();
    canvas.translate(0, canvas.getHeight());

    mPipe.put(ms);
    mPipe.reset();
    int x = 0;
    Float t;
    while ((t = mPipe.next()) != null) {
        float height = (t * mFactor);
        mPath.lineTo(x, -height);
        x += mTransX;
    }
    canvas.drawPath(mPath, mPaint);
}
 
开发者ID:android-notes,项目名称:renderingPerformance,代码行数:17,代码来源:PolylineChartPagePerformance.java

示例6: dispatchDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mAdapter == null || headers.isEmpty()) {
        return;
    }
    for (View header : headers) {
        int saveCount = canvas.save();
        int top = (Integer)header.getTag();
        canvas.translate(LocaleController.isRTL ? getWidth() - header.getWidth() : 0, top);
        canvas.clipRect(0, 0, getWidth(), header.getMeasuredHeight());
        if (top < 0) {
            canvas.saveLayerAlpha(0, top, header.getWidth(), top + canvas.getHeight(), (int)(255 * (1.0f + (float)top / (float)header.getMeasuredHeight())), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
        }
        header.draw(canvas);
        canvas.restoreToCount(saveCount);
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:19,代码来源:LetterSectionsListView.java

示例7: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
public void draw(Canvas canvas) {
    if (mDrawable == null || !mEnabled) {
        return;
    }
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    canvas.scale(mScaleX, mScaleY, mPositionX, mPositionY);
    canvas.translate(mTranslationX + mPositionX, mTranslationY + mPositionY);
    canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
    mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
    mDrawable.draw(canvas);
    canvas.restore();
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:13,代码来源:TargetDrawable.java

示例8: drawBounce

import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawBounce(Canvas canvas) {
    canvas.save();
    canvas.translate(mDataBean.mLaunchXRaw, mDataBean.mLaunchYRaw);
    canvas.rotate(mDataBean.mRotateDegrees, 0, 0);
    canvas.translate(-mDataBean.mClickViewRect.width(), -mDataBean.mClickViewRect.height() / 2.0f);
    drawBubble(canvas);
    canvas.restore();
    mDataBean.mElasticPath.reset();
    mDataBean.mElasticPath.moveTo(mDataBean.mStickyPointCenter0.x, mDataBean.mStickyPointCenter0.y);
    mDataBean.mElasticPath.quadTo(mDataBean.mSidesInnerBesierCtrlPoint0.x, mDataBean.mSidesInnerBesierCtrlPoint0.y,
            mDataBean.mMoveDrawPointCenter.x, mDataBean.mMoveDrawPointCenter.y);
    mDataBean.mElasticPath.quadTo(mDataBean.mSidesInnerBesierCtrlPoint1.x, mDataBean.mSidesInnerBesierCtrlPoint1.y,
            mDataBean.mStickyPointCenter1.x, mDataBean.mStickyPointCenter1.y);

    mDataBean.mElasticPath.quadTo(mDataBean.mSidesOuterBesierCtrlPoint1.x, mDataBean.mSidesOuterBesierCtrlPoint1.y,
            mDataBean.mMoveDrawPointCenter.x, mDataBean.mMoveDrawPointCenter.y);
    mDataBean.mElasticPath.quadTo(mDataBean.mSidesOuterBesierCtrlPoint0.x, mDataBean.mSidesOuterBesierCtrlPoint0.y,
            mDataBean.mStickyPointCenter0.x, mDataBean.mStickyPointCenter0.y);

    mDataBean.mPaint.setStyle(Paint.Style.FILL);
    mDataBean.mPaint.setColor(mDataBean.mElasticColor);
    mDataBean.mPaint.setStrokeWidth(1);
    mDataBean.mPaint.setMaskFilter(mDataBean.mFilter);
    canvas.drawPath(mDataBean.mElasticPath, mDataBean.mPaint);

    //画固定点的桩
    drawStickyPoints(canvas);
}
 
开发者ID:halohoop,项目名称:UsoppBubble,代码行数:29,代码来源:UsoppFrameLayout.java

示例9: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * The skew effect is handled by changing the transform of the Canvas
 * and then calling the usual superclass draw() method.
 */
@Override
public void draw(Canvas canvas) {
    if (mSkewX != 0) {
        canvas.translate(0, getHeight());
        canvas.skew(mSkewX, 0);
        canvas.translate(0,  -getHeight());
    }
    super.draw(canvas);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:14,代码来源:AnticiButton.java

示例10: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
public void draw(Canvas canvas) {
    if (isVisible()) {
        // Draw the fast scroller popup
        int restoreCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mBgBounds.left, mBgBounds.top);
        mTmpRect.set(mBgBounds);
        mTmpRect.offsetTo(0, 0);

        mBackgroundPath.reset();
        mBackgroundRect.set(mTmpRect);

        float[] radii;

        if (Utils.isRtl(mRes)) {
            radii = new float[]{mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, 0, 0};
        } else {

            radii = new float[]{mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, 0, 0, mCornerRadius, mCornerRadius};
        }

        mBackgroundPath.addRoundRect(mBackgroundRect, radii, Path.Direction.CW);

        mBackgroundPaint.setAlpha((int) (mAlpha * 255));
        mTextPaint.setAlpha((int) (mAlpha * 255));
        canvas.drawPath(mBackgroundPath, mBackgroundPaint);
        canvas.drawText(mSectionName, (mBgBounds.width() - mTextBounds.width()) / 2,
                mBgBounds.height() - (mBgBounds.height() - mTextBounds.height()) / 2,
                mTextPaint);
        canvas.restoreToCount(restoreCount);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:32,代码来源:FastScrollPopup.java

示例11: drawCachedBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawCachedBitmap(Canvas canvas) {
    canvas.translate(-mStartX, -mStartY);
    if (mPaths != null) {
        for (int i = 0; i < mPaths.size(); i++) {
            if (mColors != null && i < mColors.size()) {
                mPaint.setColor(mColors.get(i));
            }
            canvas.drawPath(mPaths.get(i), mPaint);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:PathsDrawable.java

示例12: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Paint paint) {
    float radius=getWidth()/10;
    for (int i = 0; i < 8; i++) {
        canvas.save();
        Point point=circleAt(getWidth(),getHeight(),getWidth()/2-radius,i*(Math.PI/4));
        canvas.translate(point.x,point.y);
        canvas.scale(scaleFloats[i],scaleFloats[i]);
        paint.setAlpha(alphas[i]);
        canvas.drawCircle(0,0,radius,paint);
        canvas.restore();
    }
}
 
开发者ID:leobert-lan,项目名称:UiLib,代码行数:14,代码来源:BallSpinFadeLoaderIndicator.java

示例13: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    Rect drawableBounds = getCaretDrawable().getBounds();
    int count = canvas.save();
    canvas.translate(getWidth() - drawableBounds.width(),
            getHeight() - drawableBounds.height());
    getCaretDrawable().draw(canvas);
    canvas.restoreToCount(count);
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:10,代码来源:PageIndicatorCaretLandscape.java

示例14: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // 画布整体向上偏移
        canvas.translate(0, -Utils.getStatusBarHeight(getResources()));

        stickyRadius = getStickyRadius();

        // 3、根据 dragCenter 动态计算 dragPoint 和 stickyPoint
        // dragPoint: 2圆圆心连线的垂线与 drag 圆的交点
        // stickyPoint: 2圆圆心连线的垂线与 sticky 圆的交点

        float xOffset = dragCenter.x - stickyCenter.x;
        float yOffset = dragCenter.y - stickyCenter.y;

        if (xOffset != 0) {
            // 斜率
            lineK = yOffset / xOffset;
        }
        dragPoint = GeometryUtil.getIntersectionPoints(dragCenter, dragRadius, lineK);
        stickyPoint = GeometryUtil.getIntersectionPoints(stickyCenter, stickyRadius, lineK);
        controlPoint = GeometryUtil.getPointByPercent(dragCenter, stickyCenter, 0.618f);


        // 1、绘制圆
        // 绘制拖拽圆
        canvas.drawCircle(dragCenter.x, dragCenter.y, dragRadius, paint);

        if (!isDragOutOfRange) {
            // 绘制固定圆
            canvas.drawCircle(stickyCenter.x, stickyCenter.y, stickyRadius, paint);
            // 2、使用贝塞尔曲线绘制连接部分
            Path path = new Path();
            // 设置起点
            path.moveTo(stickyPoint[0].x, stickyPoint[0].y);
            // 使用贝塞尔曲线连接
            path.quadTo(controlPoint.x, controlPoint.y, dragPoint[0].x, dragPoint[0].y);
            // 连线
            path.lineTo(dragPoint[1].x, dragPoint[1].y);
            path.quadTo(controlPoint.x, controlPoint.y, stickyPoint[1].x, stickyPoint[1].y);
//        path.close(); // 默认关闭
            canvas.drawPath(path, paint); // 绘制
        }
        // 绘制圈圈,以固定圆圆心为圆心,然后80为半径
        paint.setStyle(Paint.Style.STROKE);// 设置只有边线
        canvas.drawCircle(stickyCenter.x, stickyCenter.y, maxDistance, paint);
        paint.setStyle(Paint.Style.FILL);

    }
 
开发者ID:sleticalboy,项目名称:CustomWeight,代码行数:51,代码来源:GooView.java

示例15: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private void draw(Canvas c, RecyclerView parent)
{
    int childCount = parent.getChildCount();

    if(parent.getClipToPadding())
    {
        c.clipRect(parent.getPaddingLeft(), parent.getPaddingTop(),
                parent.getWidth() - parent.getPaddingRight(),
                parent.getHeight() - parent.getPaddingBottom());
    }

    int top = parent.getPaddingTop();
    int preHeaderId;
    int headerId = NO_POSITION;
    int x = parent.getPaddingLeft();
    for(int i = 0; i < childCount; i++)
    {
        View itemView = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(itemView);

        //只有各组第一个 并且 headerId!=-1 才绘制头部view
        preHeaderId = headerId;
        headerId = getHeaderId(position);
        if(headerId <= NO_POSITION || headerId == preHeaderId)
        {
            continue;
        }

        View header = getHeaderView(parent, position);

        int heightWithPadding = header.getHeight() + top;
        int y = Math.max(heightWithPadding, itemView.getTop());
        if(isStick)
        {
            int nextPosition = getNextHeadPosition(i, headerId, childCount, parent);
            if(nextPosition != NO_POSITION)
            {
                View nextView = parent.getChildAt(nextPosition);
                //获得真实位置后再进行判断
                parent.getDecoratedBoundsWithMargins(nextView, rect);
                //判断下一个头部view是否到了与上一个头部view接触的临界值
                //如果满足条件则把上一个头部view推上去
                if(rect.top <= heightWithPadding)
                {
                    //这里使用nextView.getTop 直接减掉 header.getHeight(),如果减去heightWithPadding,
                    //会出现移动时的间距
                    y = nextView.getTop() - header.getHeight();
                }
            }
        }

        //这个时候,y是header底部位置,需要减去它的高度,修正定位
        y -= header.getHeight();
        c.translate(x, y);
        header.draw(c);
        //修正回来
        c.translate(-x, -y);
    }
}
 
开发者ID:Ayvytr,项目名称:EasyAndroid,代码行数:61,代码来源:StickyHeaderItemDecoration.java


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