Android layout: running second layout pass

爷,独闯天下 提交于 2020-01-02 04:40:17

问题


I'm extending TextView and loading a custom typeface. I'm using this custom text view in a list view. When I scroll the list sometimes I get the following debug messages

requestLayout() improperly called by com.sample.CustomTextView{52afae4c V.ED.... ......ID 0,27-27,44 #7f060074 app:id/some_id} during layout: running second layout pass

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

However this warning is not printed if the list view is not scrolling or when its loaded first time. Do i need to override something and set any flags ?


回答1:


I don't get this error anymore and this could have been totally to do with StickyHeaderListView being used. We removed the StickyHeaderListView and used standard android ListView and everything seems to be working fine.

If you are getting this warning in logs. Try removing custom ListView if any and replace with standard Android ListView and verify that this does not happen.



来源:https://stackoverflow.com/questions/22078961/android-layout-running-second-layout-pass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!