久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='tlaqe'></tfoot>

    <legend id='tlaqe'><style id='tlaqe'><dir id='tlaqe'><q id='tlaqe'></q></dir></style></legend>

    <small id='tlaqe'></small><noframes id='tlaqe'>

      <i id='tlaqe'><tr id='tlaqe'><dt id='tlaqe'><q id='tlaqe'><span id='tlaqe'><b id='tlaqe'><form id='tlaqe'><ins id='tlaqe'></ins><ul id='tlaqe'></ul><sub id='tlaqe'></sub></form><legend id='tlaqe'></legend><bdo id='tlaqe'><pre id='tlaqe'><center id='tlaqe'></center></pre></bdo></b><th id='tlaqe'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tlaqe'><tfoot id='tlaqe'></tfoot><dl id='tlaqe'><fieldset id='tlaqe'></fieldset></dl></div>
      • <bdo id='tlaqe'></bdo><ul id='tlaqe'></ul>

      用于設置自定義字體的自定義字體的內存泄漏

      Memory leaks with custom font for set custom font(用于設置自定義字體的自定義字體的內存泄漏)
      <tfoot id='5watW'></tfoot>
      <legend id='5watW'><style id='5watW'><dir id='5watW'><q id='5watW'></q></dir></style></legend>
        <tbody id='5watW'></tbody>

          <small id='5watW'></small><noframes id='5watW'>

        • <i id='5watW'><tr id='5watW'><dt id='5watW'><q id='5watW'><span id='5watW'><b id='5watW'><form id='5watW'><ins id='5watW'></ins><ul id='5watW'></ul><sub id='5watW'></sub></form><legend id='5watW'></legend><bdo id='5watW'><pre id='5watW'><center id='5watW'></center></pre></bdo></b><th id='5watW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5watW'><tfoot id='5watW'></tfoot><dl id='5watW'><fieldset id='5watW'></fieldset></dl></div>
          • <bdo id='5watW'></bdo><ul id='5watW'></ul>

              1. 本文介紹了用于設置自定義字體的自定義字體的內存泄漏的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                以下用于設置自定義字體的代碼會降低我的整個應用程序的速度.如何修改它以避免內存泄漏并提高速度和管理內存?

                The following code for setting custom fonts slows down my whole app. how do i modify it to avoid memory leaks and increase the speed and manage memory well?

                public class FontTextView extends TextView {
                    private static final String TAG = "FontTextView";
                
                    public FontTextView(Context context) {
                        super(context);
                    }
                
                    public FontTextView(Context context, AttributeSet attrs) {
                        super(context, attrs);
                        setCustomFont(context, attrs);
                    }
                
                    public FontTextView(Context context, AttributeSet attrs, int defStyle) {
                        super(context, attrs, defStyle);
                        setCustomFont(context, attrs);
                    }
                
                    private void setCustomFont(Context ctx, AttributeSet attrs) {
                        TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.FontTextView);
                        String customFont = a.getString(R.styleable.FontTextView_customFont);
                        setCustomFont(ctx, customFont);
                        a.recycle();
                    }
                
                    public boolean setCustomFont(Context ctx, String asset) {
                        Typeface tf = null;
                        try {
                        tf = Typeface.createFromAsset(ctx.getAssets(),"fonts/"+ asset);  
                        } catch (Exception e) {
                            Log.e(TAG, "Could not get typeface: "+e.getMessage());
                            return false;
                        }
                
                        setTypeface(tf);  
                        return true;
                    }
                    }
                

                推薦答案

                你應該緩存 TypeFace,否則 你可能會冒著舊手機內存泄漏的風險.緩存也會提高速度,因為從資源中讀取并不是非常快.

                You should cache the TypeFace, otherwise you might risk memory leaks on older handsets. Caching will increase speed as well since it's not super fast to read from assets all the time.

                public class FontCache {
                
                    private static Hashtable<String, Typeface> fontCache = new Hashtable<String, Typeface>();
                
                    public static Typeface get(String name, Context context) {
                        Typeface tf = fontCache.get(name);
                        if(tf == null) {
                            try {
                                tf = Typeface.createFromAsset(context.getAssets(), name);
                            }
                            catch (Exception e) {
                                return null;
                            }
                            fontCache.put(name, tf);
                        }
                        return tf;
                    }
                }
                

                我提供了一個完整示例,說明如何加載自定義字體和樣式文本視圖作為類似問題的答案.您似乎大部分都做對了,但您應該按照上面的建議緩存字體.

                I gave a full example on how to load custom fonts and style textviews as an answer to a similar question. You seem to be doing most of it right, but you should cache the font as recommended above.

                這篇關于用于設置自定義字體的自定義字體的內存泄漏的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                Get current location during app launch(在應用啟動期間獲取當前位置)
                locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)

              2. <small id='CkbPn'></small><noframes id='CkbPn'>

                <tfoot id='CkbPn'></tfoot>
                <i id='CkbPn'><tr id='CkbPn'><dt id='CkbPn'><q id='CkbPn'><span id='CkbPn'><b id='CkbPn'><form id='CkbPn'><ins id='CkbPn'></ins><ul id='CkbPn'></ul><sub id='CkbPn'></sub></form><legend id='CkbPn'></legend><bdo id='CkbPn'><pre id='CkbPn'><center id='CkbPn'></center></pre></bdo></b><th id='CkbPn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='CkbPn'><tfoot id='CkbPn'></tfoot><dl id='CkbPn'><fieldset id='CkbPn'></fieldset></dl></div>
                <legend id='CkbPn'><style id='CkbPn'><dir id='CkbPn'><q id='CkbPn'></q></dir></style></legend>

                    <bdo id='CkbPn'></bdo><ul id='CkbPn'></ul>

                      <tbody id='CkbPn'></tbody>

                        1. 主站蜘蛛池模板: 国产精品久久国产精品久久 | 亚洲高清在线视频 | 91社区在线高清 | 亚洲伊人a | 国产精品久久久久久婷婷天堂 | 欧美中文在线 | 日本精品久久久久久久 | 综合成人在线 | 91成人 | 亚洲视频在线播放 | 国内毛片毛片毛片毛片 | 色狠狠一区 | www.日韩 | 免费在线观看毛片 | 久久蜜桃av一区二区天堂 | 欧美激情国产日韩精品一区18 | 看一级毛片视频 | 欧美性成人| 国产一区| 一区在线观看 | 偷拍第一页| 欧美性影院 | 一区二区av| 777毛片| 黄a大片 | 天堂综合网久久 | www.欧美| 国产一区三区在线 | 国产精品视频久久 | 色婷婷一区 | 久久国产一区 | 波多野结衣在线观看一区二区三区 | 免费爱爱视频 | 亚洲成人一级 | 日韩视频在线免费观看 | 国产精品久久久久久久久久久新郎 | 国产视频二区 | 国产一区二区三区四区hd | 久久国产精品72免费观看 | 久久久免费电影 | 国产精品99 |