मैं किसी दिए गए स्ट्रिंग के अवरोधक की ऊंचाई कैसे प्राप्त कर सकता हूं?मैं किसी दिए गए स्ट्रिंग के अवरोधक की ऊंचाई कैसे प्राप्त कर सकता हूं?
उदाहरण के लिए,
abc
0.abcl
लौटना चाहिए लौटना चाहिए 0.abcp
आधारभूत करने के लिए descnder रेखा से दूरी लौटना चाहिए।abclp
को अवरोही रेखा से बेसलाइन तक दूरी वापस करनी चाहिए।
सबसे अच्छा मैं अब तक बाहर आया सकता
private int getDecender(String string, Paint paint) {
// Append "l", to ensure there is Ascender
string = string + "l";
final String stringWithoutDecender = "l";
final Rect bounds = new Rect();
final Rect boundsForStringWithoutDecender = new Rect();
paint.getTextBounds(string, 0, string.length(), bounds);
paint.getTextBounds(stringWithoutDecender, 0, stringWithoutDecender.length(), boundsForStringWithoutDecender);
return bounds.height() - boundsForStringWithoutDecender.height();
}
लेकिन, मेरा कोड गंध है कि वे पर्याप्त नहीं हैं है। क्या कोई बेहतर और तेज़ तरीका है?
प्रश्न कैसे पता लगाना है, क्या कोई स्ट्रिंग है जिसमें दिए गए स्ट्रिंग के भीतर गैर-शून्य मूल है। –
क्षमा करें, मैंने बहुत जल्दी पढ़ा है। आपके पास शायद आपके कोड में सबसे अच्छा समाधान है। – emidander