2016-02-20 81 views
-1

我正在畫canavasarc但有些怎麼老是開始從左至右我是應該從中間自定義視圖不對齊中心

float x = 0.25f; 
    final float radius = x * (new Float(dpi)); 
    mRadius = Math.round(radius) + 20; 

mRect = new RectF(
      getWidth() + mStrokeWidth, getWidth() + mStrokeWidth, getWidth() + (mRadius/2) - mStrokeWidth, getWidth() + (mRadius/2) - mStrokeWidth 
    ); 
     canvas.drawArc(mRect, lastDegree, mSectionDegree, false, mPaint); 

爲什麼這種觀點總是從左路連我都給予重心仍然

開始啓動
float Degree = 270 + (mGap/2); 
    for (int i = 0; i < mTotalSections; i++) { 

     fillColor(i); 
     canvas.drawArc(mRect, Degree, mDegree, false, mPaint); 
     Degree += mDegree + mGap; 
     Paint mPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG); 
     mPaint1.setStrokeWidth(1); 
     mPaint1.setStyle(Paint.Style.FILL); 
     mPaint1.setAntiAlias(true); 
     mPaint1.setTextSize(15 * getResources().getDisplayMetrics().density); 

     mPaint1.setColor(getResources().getColor(black)); 

     mPaint1.setTextAlign(Paint.Align.CENTER); 
     canvas.drawText(text, mRect.centerX(), mRect.centerY(), mPaint1); 
    } 

回答

0

我不確定你想做什麼,但你的矩形看起來很奇怪。一個矩形更像這樣應該會更好:

mRect = new RectF(
     0 + mStrokeWidth, 0 + mStrokeWidth, getWidth() - mStrokeWidth, getHeight - mStrokeWidth 
); 

但有一點關於你想要什麼和你的角度的值將是完美的;)。如果您提供,我會編輯我的答案。

編輯: 所以,如果你想在你的自定義中間的圓圈查看您可以做這樣的事情:

RectF mRect = new RectF(
      50 + mStrokeWidth, 50 + mStrokeWidth, getWidth() -50 - mStrokeWidth, getHeight() -50 - mStrokeWidth 
    ); 

    canvas.drawArc(mRect, 0,360,false,paint); 

結果(藍線是我的觀點的限制): circle

你必須修改50以適應你想要的;)。 如果你想粘在邊緣與180度角度的一個弧:

RectF mRect = new RectF(
      mStrokeWidth, mStrokeWidth, getWidth() - mStrokeWidth, getHeight() - mStrokeWidth 
    ); 

    canvas.drawArc(mRect, 0,180,false,paint); 

結果:

Arc

讓我知道,如果你需要別的東西。

+0

所以問題是我的圈總是在左側我想它應該來到中心 – bob

+0

與此視圖是不可見的..check qus我已編輯 – bob

+0

如果你能給我一個你想要的畫,這將是完美的。 – king

相關問題