कस्टम फ़ॉन्ट्स सेट करने के लिए निम्न कोड मेरे पूरे ऐप को धीमा कर देता है। मेमोरी लीक से बचने और गति बढ़ाने और स्मृति को अच्छी तरह से प्रबंधित करने के लिए मैं इसे कैसे संशोधित करूं?सेट कस्टम फ़ॉन्ट के लिए कस्टम फ़ॉन्ट के साथ मेमोरी लीक
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;
}
}
मैं setcustomfont के लिए fontcache i nmy code कैसे कॉल करूं? मैं इसे हर बार सही नहीं कर सकता –
tf = Typeface.createFromAsset (ctx.getAssets(), "fonts /" + परिसंपत्ति) को बदलें; tf = FontCache.get ("फोंट /" + संपत्ति, सीटीएक्स) के साथ; – britzl
क्या हैशटेबल का उपयोग करने का कोई कारण है? यदि नहीं, तो 'ArrayMap' कम स्मृति खपत और पुनरावृत्ति गति के कारण एक बेहतर प्रकार हो सकता है। – wilkas