"ArcGIS Runtime SDK for Android Development note"-Problem set: Using Textsymbol to do callout display garbled

Source: Internet
Author: User

1. Preface

In 14, wrote a blog about ArcGIS for Android 10.1.1API Chinese annotation caused the program to crash the problem, but at that time did not solve such a problem, also did not delve into the cause of such an anomaly, or Chinese characters garbled, not displayed, What causes the exception display. Instead, a compromise solution is used: for situations where you want to use Textsymbol, you first convert the text information into a picture and then use the Picturesymbol display. This avoids the emergence of exceptions, but always finds that the existing solution is not positive. In addition, the group of friends also happened to study this piece, and provide the corresponding solution, as long as the text information, the font can be set.

The core code is as follows:

 textsymbol ts = new Textsymbol (18,  "Chinese markup display test, English test"  Color.red)  Ts.setfontfamily ( "Droidsansfallback.ttf") ;//Set the font 
Ts.setoffsetx (;
Ts.setoffsety (-30) ;
Graphic Gtext = new Graphic (Point,ts) ;
graphicslayer.addgraphic (Gtext) ;

But on the author's machine run a bit on the following results. (LG Nexus 4, Android version 5.0.1 native system)

Then a device was changed and tested, and the discovery of miracles was normal. (Samsung gt-p7510,android version 4.1.2 cm Edition)

Reprint Please specify source: http://www.cnblogs.com/gis-luq/p/4833361.html

2, the cause of the problem

How did the problem arise? By accessing the information, I see the following passage on the Internet.

Android system in the general Chinese and English font package, mainly Droidsansfallback.ttf (Chinese font), Droidsans.ttf (English font), Droidsans-bold.ttf (English bold font) these three kinds, because these three kinds of fonts are the Andorid system in almost every display interface to use the font, is the default system font, so as long as you are an Android phone, the general system is built with these three fonts.

But there is an exception to the estimate, because there is no such font for the custom Android system, the font is not the default is really bad, such as MIUI.  There is also the NEXUS4 display of the native Android 5.01 system when we test it is also abnormal, then why? Here I try to open the Android Device Monitor tool and check the font.

Locate the file Explorer under the Android Device Monitor tool, where the font library is located under the:/system/fonts folder.

By careful examination, found that the Android 5.01 system NEXUS4 Font Library does not have Droidsansfallback.ttf font files, and then I looked the same way to see the Samsung gt-p7510, Android version of the 4.1.2 System font library, in the font library we found the Droidsansfallback.ttf font, here will be able to explain why in the NEXUS4 font display anomalies, in the gt-p7510 show the normal reason.

There are many articles on the Internet that teach you to replace Android fonts, and in these articles we find a problem: The default Simplified Chinese font substitution for Android 5.0 system in order toNotoSansHans-Regular.otf,通过上面的检查我们也知道了Android 5.01的系统里没有DroidSansFallback.ttf字体。我想这样就是问题的关键点所在了。

Next we do a further test, replacing NotoSansHans-Regular.otf the font with the. Then the sample code is as follows:

 textsymbol ts = new Textsymbol (18,  "Chinese markup display test, English test"  Color.red)  Ts.setfontfamily ( "NOTOSANSHANS-REGULAR.OTF")  Ts.setoffsetx (0) ; 
Ts.setoffsety (-30) ;
Graphic Gtext = new Graphic (Point,ts) ;
graphicslayer.addgraphic (Gtext) ;

结果在Nexus4 上依旧中文显示乱码,有可能是otf的字体文件就没有被识别到。

To make the font appear normal. I did the following again, NEXUS4 to root, and then DroidSansFallback.ttf Copy the font file to the Phone System font folder (/system/fonts), finally succeeded. Results such as:

3, problem-handling solutions

In fact, in the analysis of the cause of the time has introduced the treatment plan, here is a simple summary.

1), Android 5.0 version, check the phone font library contains droidsansfallback.ttf font, if included, sets the font used when using Textsymbol. (It is also possible to set other fonts, but the font is supported in Chinese)

2 ", Android 5.0 or later, because the default OTF format font is not recognized, first droidsansfallback.ttf font files are copied to the Phone system font folder, and then set to use. (It is not very practical for each of the phones used to root and set)

3), for the online mention of the load custom local font solution, the key code is as follows, where the font class is typeface, I did not find the corresponding setting interface in Textsymbol, so this road is not going through. Welcome everyone to make brick supplement.

Typeface Customfont = Typeface.createfromasset (this"fonts/yourcustomfont.ttf"  = (TextView) Findviewbyid (R.id.activity_main_header); View.settypeface (Customfont);

Additional instructions: ArcGIS Runtime SDK for Android version 10.2.6-u2

4. References

Http://www.68idc.cn/help/buildlang/ask/20150102153583.html

http://www.zhihu.com/question/26202765

Http://jingyan.baidu.com/article/8275fc86b80c6d46a03cf6f9.html

Http://my.oschina.net/ryanhoo/blog/260945?p=1

ArcGIS Runtime SDK for Android Development note-Problem set: Label display garbled with Textsymbol

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.