要使用或不使用自定义字体在Android自定义、要使、或不、字体

2023-09-05 10:17:50 作者:社会已入少年心

我在想,是什么优点(除了有一个differenciating字体),并根据使用自定义字体的产品的商标用它做什么?

I was wondering, what are the advantages (besides having a differenciating font) and making using it according the the trademark of a product of using a custom font?

但更重要的,什么是真正的缺点?我看了这个答案 http://stackoverflow.com/a/4734610/327011 至少OTF有问题,一些其中根据PPI manifestat更加中的特定设备。

But more important, what are the real disadvantages? I read in this answer http://stackoverflow.com/a/4734610/327011 that at least OTF has problems, some of which manifestat even more in specific devices according to the PPI.

所以,对于那些谁使用,谁做不是因为他们不认为他们应该,你有什么意见和论据?

So, for those who have use and those who don't because they don't think they should, what are your opinions and arguments?

感谢

推荐答案

此外什么CommonsWare说,(这是我的第一个公认的答案),我发现了一个重大的错误,在使用自定义字体时创建内存泄漏:

Besides what CommonsWare said, (that was my first accepted answer), I have found a major bug, that creates memory leaks when using Custom Fonts:

的http:// code。 google.com/p/android/issues/detail?id=9904#c7

由于这个原因,我倾向于认为这不是一个好IDEIA使用它们..或者当您使用它们至少要小心!

Because of this, I tend to think that it is not a good ideia to use them.. or at least beware when you use them!

如果你确实需要使用它们,你可以利用这一点避免了内存泄漏的最重要的部分:

If you do need to use them, you can use this to avoid the biggest part of the memory leaks:

public class Typefaces {
    private static final String TAG = "Typefaces";

    private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();

    public static Typeface get(Context c, String assetPath) {
        synchronized (cache) {
            if (!cache.containsKey(assetPath)) {
                try {
                    Typeface t = Typeface.createFromAsset(c.getAssets(),
                            assetPath);
                    cache.put(assetPath, t);
                } catch (Exception e) {
                    Log.e(TAG, "Could not get typeface '" + assetPath
                            + "' because " + e.getMessage());
                    return null;
                }
            }
            return cache.get(assetPath);
        }
    }
}