7

मुझे Google Play पर प्रकाशित मेरे एप्लिकेशन के साथ एक गंभीर समस्या का सामना करना पड़ रहा है और स्पष्ट रूप से> 4.0 के अलावा एंड्रॉइड के सभी संस्करणों पर ठीक काम कर रहा है।नेक्सस 7 पर एंड्रॉइड 4.2: canvas.drawText() सही ढंग से काम नहीं कर रहा है

यह मेरा Android 4.0 एचटीसी फोन से एक screenshoot है:

enter image description here

और यह मैं नेक्सस 7, एंड्रॉयड 4.2.1 (एमुलेटर में समान व्यवहार) पर प्राप्त होता है:

enter image description here

मैं canvas.drawText()

का उपयोग कर तैयार की गई प्रत्येक पाठ के लिए एक ही व्यवहार देख

पाठ आकर्षित करने के लिए इस्तेमाल किया पेंट है:

paint = new Paint(); 
paint.setAntiAlias(true); 
paint.setColor(color); //some color 
paint.setTextSize(size); //some size 
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); 
paint.setTextAlign(Align.CENTER); 

Logcat (4.2.1 एमुलेटर) में मैं

12-18 20:42:21.096: W/Trace(276): Unexpected value from nativeGetEnabledTags: 0 

का एक बहुत देखते हैं मैं प्रकट में इन सेटिंग्स का उपयोग करें:

<uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="8" /> 
+0

वास्तव में पाठ का आकार 0.175f है और मैं कैनवास backgroundCanvas.scale का उपयोग कर पैमाने (getWidth(), getWidth()); –

उत्तर

14

मैं googling के एक बहुत बाद मेरे ही सवाल का जवाब ...

चाल पेंट पाठ ड्राइंग के लिए इस्तेमाल किया वस्तु के लिए setLinearText(true) के उपयोग में मिलकर बनता है। अब, सब कुछ अच्छा लग रहा है।

paint = new Paint(); 
paint.setAntiAlias(true); 
paint.setColor(color); 
paint.setTextSize(size); 
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); 
paint.setTextAlign(Align.CENTER); 
paint.setLinearText(true); 
यहाँ

लिंक है कि मेरा दिन बचाता है:

http://gc.codehum.com/p/android/issues/detail?id=39755

मुझे आशा है कि यह someonelse कर सकते हैं।

पाठ अभी तक सबसे अच्छे रूप में प्रदान की गई है:

enter image description here

संपादित (14/01/2013)

मैं अभी भी एक Kering समस्या (केवल 4.2 पर का सामना करना पड़ रहा है। 1)। कृपया मेरे अन्य प्रश्न यहाँ देखें:

Android 4.2.1 wrong character kerning (spacing)

संपादित (05/02/2013)

मैं देख रहा हूँ एक और परियोजनाओं में एक ही समस्या है।नीचे दिए गए लिंक को देखो:

http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/

आप नेक्सस 4.2.1 पर नमूना चलाते हैं (या सिम्युलेटर Android 4.2 में) आप एक ही "अजीब" पाठ मिलता है ...

संपादित (20/02/2013)

मिले एक समाधान है कि setLinearText(true) नहीं का उपयोग करता है, यहाँ देखो:

Android 4.2.1 wrong character kerning (spacing)

+0

धन्यवाद, धन्यवाद, धन्यवाद! तुमने मुझे पागलपन से बचाया! यह अंत में setLinearText (सत्य) के साथ काम करता है। काश वे देवताओं के लिए इन एपीआई परिवर्तनों को बेहतर दस्तावेज करेंगे। 4.2.1 के लिए काम करने में मुझे 2 सप्ताह लग गए। Grrr .... – ssuperz28

+0

मुझे खुशी है कि मैं इस मुद्दे के साथ अकेला नहीं हूं ... जैसा कि आप देख सकते हैं, चरित्र कर्नाई गलत लगता है (चरित्र अंतर 0 है)। क्या आपकी भी यही समस्या है? मेरा अन्य प्रश्न यहां: http://stackoverflow.com/questions/13974129/android-4-2-1-worng-character-kerning-spacing –

0

एंड्रॉइड 4 हार्डवेयर त्वरण पर डिफ़ॉल्ट है। कुछ ड्राइंग फ़ंक्शंस इस पर ठीक से काम नहीं करते हैं। याद नहीं कर सकते कि कौन से लोग बिल्कुल प्रकट होते हैं लेकिन मैनिफेस्ट फ़ाइल में हार्डवेयर त्वरण को बंद करने का प्रयास करते हैं और देखें कि इससे कोई फर्क पड़ता है या नहीं।

बेशक यह कारण नहीं हो सकता है लेकिन यह एक कोशिश के लायक है।

+0

धन्यवाद। दुर्भाग्य से टैग एंड्रॉइड: हार्डवेयर एक्सेलेरेटेड एंड्रॉइड 3.0 के नीचे पहचाना नहीं गया है, इसलिए मैं इसे अपने एप्लिकेशन (एंड्रॉइड 2.3.3) के लिए उपयोग नहीं कर सकता ... –

+0

यदि आप एंड्रॉइड 3 या 4 के खिलाफ संकलित कर सकते हैं तो आप कर सकते हैं। इसे उन संस्करणों पर अनदेखा कर दिया जाएगा जो इसका समर्थन नहीं करते हैं। (प्रोजेक्ट बिल्ड लक्ष्य को अपनी मेनिफेस्ट फ़ाइल नहीं बदलें) – Kuffs

+0

ठीक है, मैंने एंड्रॉइड एसडीके 3.2, एंड्रॉइड का उपयोग किया: हार्डवेयर एक्सेलेरेटेड = "झूठा" पुनः संकलित और एक ही समस्या प्राप्त करना। –

1

मुझे एक ही समस्या थी, कस्टम लेटर स्पेसिंग के साथ एक दृश्य बनाने की कोशिश कर रहा था, इसलिए मैंने अभी यह 2 विधियां बनाई हैं, उम्मीद है कि कोई उन्हें उपयोगी लगेगा।

/** 
* Draws a text in the canvas with spacing between each letter. 
* Basically what this method does is it split's the given text into individual letters 
* and draws each letter independently using Canvas.drawText with a separation of 
* {@code spacingX} between each letter. 
* @param canvas the canvas where the text will be drawn 
* @param text the text what will be drawn 
* @param left the left position of the text 
* @param top the top position of the text 
* @param paint holds styling information for the text 
* @param spacingPx the number of pixels between each letter that will be drawn 
*/ 
public static void drawSpacedText(Canvas canvas, String text, float left, float top, Paint paint, float spacingPx){ 

    float currentLeft = left; 

    for (int i = 0; i < text.length(); i++) { 
     String c = text.charAt(i)+""; 
     canvas.drawText(c, currentLeft, top, paint); 
     currentLeft += spacingPx; 
     currentLeft += paint.measureText(c); 
    } 
} 

/** 
* returns the width of a text drawn by drawSpacedText 
*/ 
public static float getSpacedTextWidth(Paint paint, String text, float spacingX){ 
    return paint.measureText(text) + spacingX * (text.length() - 1); 
} 
संबंधित मुद्दे