“requestLayout() improperly called by…” error on Android 4.3

前端 未结 5 2272
一个人的身影
一个人的身影 2020-12-30 21:57

I have a simple Custom TextView that sets custom font in its constructor like the code below

public class MyTextView extends TextView {

    @Inject CustomTy         


        
5条回答
  •  执笔经年
    2020-12-30 22:34

    Looking into the Android source, this problem is described in a little more detail:

    requestLayout() was called during layout. If no layout-request flags are set on the requesting views, there is no problem. If some requests are still pending, then we need to clear those flags and do a full request/measure/layout pass to handle this situation.

    It appears that the problem may be related to Roboguice; see issue #88. The suggested solution there is to use @InjectView:

    You can now use @InjectView from inside a view class. Just call Injector.injectMembers() after you've populated your view, ala:

    public class InjectedView extends FrameLayout {
    
        @InjectView(R.id.view1) View v;
    
        public InjectedView(Context context) {
            super(context);
            final View child = new View(context);
            child.setId(R.id.view1);
            addView(child);
    
            RoboGuice.getInjector(context).injectMembers(this);
        }
    }
    

    Perhaps you should consider migrating RoboGuice.injectMembers(context, this) to the declaration of your View object using the @InjectView annotation.

提交回复
热议问题