“requestLayout() 被...调用不当"Android 4.3 上的错误 [英] "requestLayout() improperly called by..." error on Android 4.3

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

问题描述

我有一个简单的自定义 TextView,它在其构造函数中设置自定义字体,如下面的代码

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

从 Gingerbread 到 JB 4.2 都可以正常工作.但是,当我在 Android 4.3 手机上显示我的自定义文本视图时,adb logcat 中充斥着以下消息.

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?

感谢您的帮助.

推荐答案

我找到了我的应用程序中出现此错误的位置.尽管在您提供的代码中没有发现这种情况(如果您在代码的其他地方这样做可能会有所帮助),但它有望帮助其他人解决这个无法追踪的问题.

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

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 上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆