久久久久久久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. 主站蜘蛛池模板: 久久青| 麻豆久久久久久 | 亚洲综合色 | 日韩在线中文字幕 | 欧美在线视频网站 | 国产高清精品一区二区三区 | 亚洲视频免费一区 | 欧美涩涩网 | 人人种亚洲 | 亚洲精品一区二区二区 | 亚洲国产看片 | 日韩国产中文字幕 | 日韩视频一区二区 | 日韩另类视频 | 欧美一区二区三区在线看 | 国产乱码精品一区二区三区中文 | 亚洲社区在线 | 99亚洲精品 | 久久国产99| 亚洲精品资源 | 四虎影院免费在线播放 | 亚洲精品视频在线播放 | 亚洲精品片 | 男人的天堂久久 | 国产亚洲精品美女久久久久久久久久 | 亚洲永久| 欧美日韩精品专区 | 日本二区在线观看 | 国产精品视频久久 | 久久高清精品 | 日韩一区二区三区在线 | 超碰超碰 | 国产91精品久久久久久久网曝门 | 成人激情免费视频 | 国产午夜精品视频 | 欧美一区二区在线观看 | 免费黄色在线 | 久久久久久久久久久一区二区 | 国产精品一二区 | 久久伦理中文字幕 | 亚洲国产日韩欧美 |