2014-11-04 8 views
8

कैनवास पर काम नहीं कर रहा है। DrawTextOnPath लॉलीपॉप डिवाइस पर काम नहीं कर रहा है। यहां अंतर देखें।Canvas.drawTextOnPath (...) लॉलीपॉप

Image

कोड एक सरल मार्ग आकर्षण है (नेक्सस 10 छवि सही है लेकिन लॉलीपॉप सही ढंग से प्रदर्शित नहीं करता है)।

// Path for the inner circle 
unitPath = new Path(); 
unitPath.addArc(unitRect, 180.0f, 180.0f); 

// Draw the text and the path 
canvas.drawTextOnPath("Inner Circle", unitPath, 0.0f, 0.0f, unitPaint); 
canvas.drawPath(unitPath,unitPaint); 

एंड्रॉयड स्टूडियो परीक्षण परियोजना इस मुद्दे को दर्शाता हुआ कोई भी व्यक्ति उसे देखना चाहता है के लिए यहाँ देखा जा सकता। https://dl.dropboxusercontent.com/u/6768304/WebLinks/TestApp.rar

क्या इस डिवाइस पर मुझे कुछ "अलग" करने की ज़रूरत है?

+0

क्या आप पूरी तरह से सुनिश्चित हैं कि पथ सही है? पथ का स्रोत क्या है? –

+0

यह वही ऐप है जो दोनों उपकरणों पर चल रहा है। आप तस्वीर में पथ देख सकते हैं। उपरोक्त कोड की अंतिम 2 पंक्तियां आंतरिक सर्कल टेक्स्ट और भरे अर्द्ध सर्कल हैं। – Kuffs

उत्तर

3

ठीक तो ऐसा लगता है कि DrawTextOnPath एक छोटे से नीचे 1.0f

फ़ॉन्ट आकार के साथ अब टूट समाधान सब कुछ पैमाने पर करने, आकर्षित पाठ तो इसे छोटा वापस नीचे जाता है।

डेमो परियोजना म drawTitle विधि इस से बदल जाएगा:

private void drawTitle(Canvas canvas) { 
    canvas.drawTextOnPath(upperTitle, upperTitlePath, 0.0f, 0.02f, unitPaint); 
    canvas.drawTextOnPath(lowerTitle, lowerTitlePath, 0.0f, 0.0f, unitPaint); 
    canvas.drawTextOnPath(unitTitle, unitPath, 0.0f, 0.0f, unitPaint); 
    canvas.drawPath(unitPath,unitPaint); 
} 

यह करने के लिए:

private void drawTitle(Canvas canvas) { 
    //Save original font size 
    float originalTextSize = unitPaint.getTextSize(); 

    // set a magnification factor 
    final float magnifier = 100f; 

    // Scale the canvas 
    canvas.save(); 
    canvas.scale(1f/magnifier, 1f/magnifier); 

    // create new rects and paths based on the new scale 
    unitRect = new RectF(); 
    unitRect.set((faceRect.left + unitPosition) * magnifier, (faceRect.top + unitPosition) * magnifier, (faceRect.right - unitPosition) * magnifier, (faceRect.bottom - unitPosition) * magnifier); 
    unitPath = new Path(); 
    unitPath.addArc(unitRect, 180.0f, 180.0f); 

    titleRect = new RectF(); 
    titleRect.set((faceRect.left + titlePosition) * magnifier, (faceRect.top + titlePosition) * magnifier, (faceRect.right - titlePosition) * magnifier, (faceRect.bottom - titlePosition) * magnifier); 
    upperTitlePath = new Path(); 
    upperTitlePath.addArc(titleRect, 180.0f, 180.0f); 

    titleRect = new RectF(); 
    titleRect.set((faceRect.left + titlePosition) * magnifier, (faceRect.top + titlePosition) * magnifier, (faceRect.right - titlePosition) * magnifier, (faceRect.bottom - titlePosition) * magnifier); 
    lowerTitlePath = new Path(); 
    lowerTitlePath.addArc(titleRect, -180.0f, -180.0f); 

    // increase the font size 
    unitPaint.setTextSize(originalTextSize * magnifier); 

    // do the drawing of the text 
    canvas.drawTextOnPath(unitTitle, unitPath, 0.0f, 0.0f, unitPaint); 
    canvas.drawTextOnPath(upperTitle, upperTitlePath, 0.0f, 0.02f, unitPaint); 
    canvas.drawTextOnPath(lowerTitle, lowerTitlePath, 0.0f, 0.0f, unitPaint); 

    // bring everything back to normal 
    canvas.restore(); 
    unitPaint.setTextSize(originalTextSize); 

    canvas.drawPath(unitPath, unitPaint); 
} 
+0

आपने मेरे जीवन दोस्त को बचाया..धन्यवाद :) – bakriOnFire

0

हाँ, लॉलीपॉप के रूप में टूट। 4.4.4 में पूरी तरह से काम किया।

https://code.google.com/p/android/issues/detail?id=40965

मैं, अगर यह छोटा था पाठ का आकार 5.f के लिए सेटिंग कैनवास का आकार छोटा करने, और आधारभूत पथ स्केलिंग उचित रूप से कर रहा हूँ। धीमा लेकिन यह काम करता है, तब तक इंतजार नहीं कर सकता जब तक कि मैं इस भयानक झुकाव को हटा नहीं सकता।

संबंधित मुद्दे