android - Android 4.3 上的 "requestLayout() improperly called by..."错误

标签 android android-layout textview android-custom-view

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

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 手机上显示我的自定义 TextView 时,adb logcat 中充斥着以下消息。

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 上发生?

感谢您的帮助。

最佳答案

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

我有一条线(当然不是我添加的):

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

在我的应用程序中,我不需要任何监听器,因此删除整个 block 可以解决此问题。对于那些需要这样的东西的人,请记住在布局更改后(在此回调内部)删除监听器。

关于android - Android 4.3 上的 "requestLayout() improperly called by..."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19170863/

相关文章:

java - 反射访问最终静态变量而不进行初始化

android - 运行 "cordova build android"- 无法找到属性 android :fontVariationSettings and android:ttcIndex

android - Cocos2d-x:可以使用 HTML(UIWebView)吗?

android - 更新小部件中的 textView

android - 如何在您的应用程序中显示特殊字符?

java - 有关如何将 Vysper xmpp 与 smack 结合使用的示例

相当于 HTML HR 标签的 Android 布局?

android - 带有 CardView 的 RecyclerView 在滚动时滞后

android - 动态改变状态栏颜色而不失去透明度

java - 通过括号转换为字符串会导致 Android 崩溃