相关疑难解决方法(0)

"在Android 4.3上错误地调用了'requestLayout()"错误

我有一个简单的自定义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);
    }
}
Run Code Online (Sandbox Code Playgroud)

从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
Run Code Online (Sandbox Code Playgroud)

我注意到,它确实减慢了UI的速度.有什么想法为什么会在4.3上发生?

感谢您的帮助.

android textview android-custom-view android-layout

26
推荐指数
2
解决办法
2万
查看次数

跟踪:requestLayout()调用不正确?

任何人都可以告诉我如何修复以下跟踪:

W/View    (16810): requestLayout() improperly called by 
theme.effects.TopCenterImageView{41dc73f0 V.ED.... ........ 
0,0-480,690 #7f060066 app:id/normal_image} during second 
layout pass: posting in next frame
Run Code Online (Sandbox Code Playgroud)

这是TopCenterImageView的代码:

public class TopCenterImageView extends ImageView {

public TopCenterImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScaleType(ScaleType.MATRIX);
}

public TopCenterImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setScaleType(ScaleType.MATRIX);
}

public TopCenterImageView(Context context) {
    super(context);
    setScaleType(ScaleType.MATRIX);
}

@Override
protected boolean setFrame(int l, int t, int r, int b) {
    if (getDrawable() == null) {
        return super.setFrame(l, t, r, b); …
Run Code Online (Sandbox Code Playgroud)

android stack-trace

18
推荐指数
1
解决办法
2万
查看次数

requestLayout()由android.widget.RelativeLayout android不正确地调用

我在显示listview时实现了listview customadapter,它显示了如何重新启动它.

requestLayout() improperly called by android.widget.RelativeLayout{b42acc20 V.E..... ......ID 0,-52-480,0 #7f0700ec app:id/ptr_id_header} during layout: running second layout pass
Run Code Online (Sandbox Code Playgroud)

java代码

public View getView(int position, View convertView, ViewGroup parent)
{
    View view = convertView;
    if (view == null)
    {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.listitemrow, null);
    }
    RssItem rssItem = mRssItemList.get(position);
    if (rssItem != null)
    {
        TextView title = (TextView) view.findViewById(R.id.rowtitle);
        if (title != null)
        {
            title.setText(rssItem.getTitle());
        }
    }
    return view;
}
Run Code Online (Sandbox Code Playgroud)

java android android-listview android-adapterview

8
推荐指数
1
解决办法
1万
查看次数

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

我正在扩展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)

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

performance android android-layout android-listview

5
推荐指数
1
解决办法
6356
查看次数