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