Android布局:运行第二个布局传递

ksa*_*kar 5 performance android android-layout android-listview

我正在扩展TextView并加载自定义字体.我在列表视图中使用此自定义文本视图.当我滚动列表时,有时我得到以下调试消息

requestLayout()在布局期间由com.sample.CustomTextView {52afae4c V.ED .... ...... ID 0,27-27,44#7f060074 app:id/some_id}不正确地调用:运行第二个布局传递

public class CustomTextView extends TextView {

private FontType mFontType;

public CustomTextView(Context context, AttributeSet attrs) {
    super(context, attrs, 0);
    if(!isInEditMode()){
        TypedArray attributesArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomTextView, 0, 0);
        try{
            mFontType = FontType.values()[attributesArray.getInteger(R.styleable.CustomTextView_fontType, 0)];
            setFontType(mFontType);
            setTypeface(Cache.getCustomTypeface(mContext, LIGHT));
            // Note: This flag is required for proper typeface rendering
            setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
        }finally {
            attributesArray.recycle();
        }
    }
}
}
Run Code Online (Sandbox Code Playgroud)

但是,如果列表视图未滚动或第一次加载时,则不会打印此警告.我需要覆盖一些东西并设置任何标志吗?

ksa*_*kar 2

我不再收到此错误,这可能完全与使用 StickyHeaderListView 有关。我们删除了 StickyHeaderListView 并使用标准的 android ListView,一切似乎都工作正常。

如果您在日志中收到此警告。尝试删除自定义 ListView(如果有)并替换为标准 Android ListView,并验证这种情况不会发生。