I have a simple Custom TextView that sets custom font in its constructor like the code below
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);
}
}
It works fine from Gingerbread through JB 4.2. But the adb logcat is flooded with the following messages when I show my custom textview on Android 4.3 phone.
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
I notice, it does slow down UI a bit. Any ideas why it's happening on 4.3?
Appreciate your help.
I met the same problem. That's because I was trying to set a view's position in the iOS way. You know in iOS set a view's position by set the view's left top value and width, height. But in Android, it should be (left, top, right, bottom). I did pay much attention on this. When I jump into the
layout()
definition, I read the method's comment, then I find out why the warning happened.Please check weather the Id of any view is repeating inside the same activity context. I was also getting the same warning, I was using a TextView repeatedly a loop with same id. I resolved the problem by using different ids each time.
I found where this bug occurs in my app. Although occurrence of this is not found in the code you provided (it may help if you have done this elsewhere in your code), it will hopefully help others fix this impossible-to-trace problem.
I had a line (not added by me, of course):
In my app, I did not need any listener, so removing this entire block fixed this problem. For those that need something like this, remember to remove the listener after the layout has changed (inside of this callback).
Looking into the Android source, this problem is described in a little more detail:
It appears that the problem may be related to Roboguice; see issue #88. The suggested solution there is to use @InjectView:
Perhaps you should consider migrating
RoboGuice.injectMembers(context, this)
to the declaration of your View object using the @InjectView annotation.I fixed these warnings in my custom
ListView
item (LinearLayout
subclass). This class implementsCheckable
, and has asetChecked(boolean checked)
method that is called to indicate whether the item is checked:I visually indicate the checked state by calling
setTypeFace()
on a textView in my view, toggling between regular and bold typefaces. ThesesetTypeFace()
calls were causing the warnings.To fix the problem, I created instance variables for the
Typeface
s in the class constructor and used them later, when changing the typeface, rather than callingTypeface.createFromAsset(...)
every time:This is a pretty specific scenario, but I was pleasantly surprised to find a fix and maybe someone else is in the same situation.