本文介绍了" requestLayout()不正确地调用..."在Android 4.3的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的自定义的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).

这篇关于" requestLayout()不正确地调用..."在Android 4.3的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:34