" requestLayout()不正确地调用..."在Android 4.3的错误正确地、错误、requestLayout、QUOT

2023-09-13 00:05:08 作者:心上一道疤而已

我有一个简单的自定义的TextView,设置自定义的字体在其构造如code以下

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);
    }
}

它通过JB 4.2正常工作的姜饼。但亚行logcat上充斥着,当我展示在Android 4.3手机我自定义的TextView下面的消息。

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

我注意到,它并减慢UI一点。任何想法,为什么它的发生在4.3?

I notice, it does slow down UI a bit. Any ideas why it's happening on 4.3?

鸭preciate你的帮助。

Appreciate your help.

推荐答案

我发现,其中这个错误发生在我的应用程序。虽然这不回答你直接提供的code(它可以帮助你做到这一点其他地方在code)中,希望能帮助别人解决这个问题不可能到轨迹的问题。

I found where this bug occurs in my app. Although this does not answer the code you provided directly (it may help if you do 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):

myView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
        //this would then make a call to update another view's layout.
    }
});

在我的应用程序,我并不需要任何监听器,以便消除这一整块修正了这个问题。对于那些需要这样的事情,记得删除监听器后的布局发生了变化(这里面回调)。

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).

 
精彩推荐
图片推荐