2012-10-24 51 views
2

我對標準方法canvas.drawCircle有一個奇怪的問題。canvas.drawCircle不起作用 - 當drawLine工作時 - 可能是使用Sherlock導致的?

雖然我在Android 4.0.4上運行完全相同的代碼在三星Galaxy S3上,而在另一個S2上運行2.1,它的工作原理沒有問題。在調用drawCircledrawPath時,帶有4.0.3的Acer 500平板電腦上的相同代碼不會繪製任何內容。

這是代碼:

Paint thickLine = new Paint(scalePaint); 
    thickLine.setStrokeWidth(0.07f); 
    thickLine.setColor(Color.argb(0xff, 0xff, 0x36, 0x33)); 
    thickLine.setFlags(Paint.ANTI_ALIAS_FLAG); 
    canvas.drawLine(0.5f, 0.5f, 0.1f, 0.1f, thickLine); 
    canvas.drawCircle(0.5f, 0.5f, 0.15f, thickLine); 

drawLine作品在所有這三個設備!

此外,我剛纔提到的代碼 - 之後我將標準片段更改爲SherlockFragments,並在幾處修改了應用中的代碼 - 總是在S3上進行測試。所以我不知道在哪個階段宏基開始不再工作了。

我還使用了包含此代碼的舊版本的繪圖類(在對應用進行所有更改之前),並將其複製到現在使用Sherlock的新版本中 - 即使項目代碼的此階段不再工作描述。

所以我想它可能是與福爾摩斯 - 但是,我沒有任何想法如何以及爲什麼 - 如果在所有....

人有一些類似的體驗,drawLine的作品,但drawCircledrawPath不? - 使用或不使用福爾摩斯

非常感謝

+1

我可以告訴你,這與ActionBarSherlock無關。 –

+0

非常感謝你,現在我可以專注於我所做的所有其他修改......另外,順便說一句,超級工作 - 我最近纔開始使用Sherlock - 但它很棒。非常感謝! – user387184

回答

1

幾乎unbelieveble但真實的,只是改變了目標設定(或產品總數刪除),它會工作 - 它在我的情況做了:-)

+0

我可以問一下你的目標設置是從什麼開始的,以及你改變了它以使它起作用嗎?我在Android 4.0.4中遇到了drawPath()方面的問題,它不是繪圖(但在早期版本中) – Kerry

+0

現在我擁有的是這樣的: 也設定了目標,但它沒有工作 – user387184

+0

感謝您的回覆。我嘗試過用SDK版本弄弄,但沒有運氣。但在我的情況下,我發現Canvas.scale()在Android 4.0之前和之後的表現並不一樣。 – Kerry

1

我有完全相同的問題 - Canvas.drawCircle不適合我。幸運的是,還有另外一個功能 - Canvas.drawOval。您可以使用它繪製圓而不更改構建目標。

RectF tmpRect = new RectF(); 
tmpRect.top = 0; 
tmpRect.bottom = diameter; 
tmpRect.left = 0; 
tmpRect.right = diameter; 

//This call will draw nothing 
canvas.drawCircle(tmpRect.centerX(), tmpRect.centerY(), tmpRect.width()/2, selectionPaint); 
//This call will draw a circle 
canvas.drawOval(tmpRect, selectionPaint); 
0

我只是有Canvas.drawLine()和Canvas.drawRect()這個問題。我的線將被繪製,但我的矩形不是。

protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    paint.setStyle(Paint.Style.FILL); 
    paint.setColor(Color.WHITE); 

    int height = canvas.getHeight(); 
    int width = canvas.getWidth(); 

    canvas.drawLine(width/2,0,width/2,height,paint); 
    canvas.drawLine(0,height/2,width,height/2,paint); 

    paint.setStyle(Paint.Style.STROKE); 
    paint.setColor(Color.GREEN); 
    canvas.drawRect(touchRect, paint); 
} 

然而,開始時,我把到View.invalidate()的調用到我的onTouchEvent()方法,因爲我想畫一個矩形,在那裏我接觸屏幕工作。

@Override 
public boolean onTouchEvent(MotionEvent event) { 

    invalidate(); 

    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     float x = event.getX(); 
     float y = event.getY(); 

     touchRect.left = (int) (x - 20); 
     touchRect.top =(int) (y - 20); 
     touchRect.right = (int) (x + 20); 
     touchRect.bottom = (int) (y + 20); 
    } 
    return false; 
} 

我得到這個從閱讀https://developer.android.com/guide/topics/graphics/2d-graphics.html

0

我不得不改變最小Android版本後,同樣的問題,從2.3到3線工作,但不是的drawRect如果我改變了Android版本都回來再次合作。 經過很多嘗試和錯誤,我發現切換頂部和buttom座標做了伎倆。

我改變了從左上角到右下角到左下角的順序,它工作。

相關問題