我有一個簡單的自定義的TextView,設置自定義字體在其構造像下面錯誤「requestLayout()不正確的...所謂的」在Android 4.3
public class MyTextView extends TextView {
@Inject CustomTypeface customTypeface;
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
RoboGuice.injectMembers(context, this);
setTypeface(customTypeface.getTypeface(context, attrs));
setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}
它通過JB 4.2正常工作從薑餅代碼。但是當我在Android 4.3手機上顯示自定義文本視圖時,adb logcat充斥着以下消息。
10-05 16:09:15.225: WARN/View(9864): requestLayout() improperly called by com.cmp.views.MyTextView{42441b00 V.ED.... ......ID 18,218-456,270 #7f060085 app:id/summary} during layout: running second layout pass
10-05 16:09:15.225: WARN/View(9864): requestLayout() improperly called by com.cmp.views.MyTextView{423753d0 V.ED.... ......ID 26,176-742,278 #7f060085 app:id/summary} during layout: running second layout pass
我注意到,它確實減慢了UI。任何想法爲什麼它發生在4.3?
感謝您的幫助。
您是否曾嘗試在視圖的生命週期中稍後移動'setTypeface()'和/或'setPaintFlags()',比如'onFinishInflate()'或其他東西?我的猜測是'setTypeface()'正在觸發一個'requestLayout()',因爲它們可能不希望它在視圖構造函數中被調用。 – CommonsWare
我試圖將它移動到onFinishInflate(),這也沒有幫助。我在日誌中看到這些requestLayout()消息 – Sanjay
MyTextView的唯一目的是設置自定義字體嗎?創建自定義視圖來設置cutom字體不是一個好的解決方案。 – GareginSargsyan