當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。