安卓:requestLayout()不正确地称为 [英] Android: requestLayout() improperly called

查看:302
本文介绍了安卓:requestLayout()不正确地称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图夸大一个 ListView控件中的布局时,会出现以下错误

requestLayout() improperly called by android.widget.TextView{...} during layout: running second layout pass

我试图抬高内布局的的ListView 如下:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null){
        LayoutInflater inflater = (LayoutInflater) musicActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_item, parent, false);
        ...
    }else{...}
}

被充气的布局可以看看简单,只要以下内容,仍然会产生误差

The layout being inflated can look as simple as the following, and will still produce the error

<TextView
    android:id="@+id/txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="@dimen/txt_size"/>

我已经看过了类似的问题,也没有找到解决办法似乎工作<一个href="http://stackoverflow.com/questions/21249935/requestlayout-improperly-called-by-android-widget-relativelayout-android">Question 1 ,问题2 ,<一个href="http://stackoverflow.com/questions/19170863/requestlayout-improperly-called-by-error-on-android-4-3">Question 3 。

有谁知道是什么原因导致这种类型的错误?任何故障排除建议?欲了解更多的背景下,这个的ListView 是在片段 ViewPager

Does anyone know what causes this type of error? Any troubleshooting advice? For more context, this ListView is displayed within a Fragment within a ViewPager

下面是完整的XML布局(减去一组属性),仍然导致问题

Here is the full XML Layout (minus a bunch of attributes), that still results in the problem

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <TextView
    android:id="@+id/txt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

 <TextView
    android:id="@+id/txt2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

 <TextView
    android:id="@+id/txt3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/txt4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

</RelativeLayout>

在此基础上

,我认为XML本身是没有问题的,除非它有做的,我使用的是ViewPager和片段

Based on this, I would think the XML itself is not a problem, unless it has to do with the fact that I am using a ViewPager and Fragments

推荐答案

这个问题似乎是在Android实现中的错误,请参见:<一href="https://$c$c.google.com/p/android/issues/detail?id=75516">https://$c$c.google.com/p/android/issues/detail?id=75516

This issue seems to be a bug in the android implementation, please see: https://code.google.com/p/android/issues/detail?id=75516

通过 ListView.setFastScrollEnabled激活在code进行的ListView 的快速滚动功能(真正的)将触发这个漏洞,你会开始看到

Activating the fast scroll feature of a ListView in your code via ListView.setFastScrollEnabled(true) will trigger this bug and you'll start seeing the

requestLayout()不正确地调用android.widget.TextView {...}   布局过程:运行第二布局传递

requestLayout() improperly called by android.widget.TextView{...} during layout: running second layout pass

在控制台的消息。

这个错误必须已在奇巧(4.4.x)更新的一个介绍,因为我还没有看到它与最初的奇巧(4.4.0)发布。除了难看控制台发送垃圾邮件从上面的调试消息,似乎有没有其他方面的影响(也许表现在某些情况下,我还没有测试过)。

This bug must have been introduced in one of the KitKat (4.4.x) updates, as I've not seen it with the initial KitKat (4.4.0) release. Apart from the ugly console spamming with the debug message from above, there seem to be no other impacts (maybe performance in some cases, which I haven't tested).

干杯

PS:这不是第一次快速滚动功能被窃听,如: <一href="https://$c$c.google.com/p/android/issues/detail?id=63545">https://$c$c.google.com/p/android/issues/detail?id=63545, 63545固定在奇巧4.4.3,但75516 poped了以后 - >似乎是谷歌一个争​​论不休的课题; - )

PS: it's not the first time that the fast scroll feature is bugged, e.g. https://code.google.com/p/android/issues/detail?id=63545, 63545 was fixed in KitKat 4.4.3 but 75516 poped up thereafter --> seems to be a vexed subject for google ;-)

修改2015年5月12号:

我更新了我的Nexus 7至Android 5.1的一些分钟前(正在运行5.0之前),停在这个新版本中看到了这个问题。由于FastScroll指标在5.1也改变了模样,我认为谷歌修复了这个问题,或者至少评论指出,垃圾邮件控制台那些丑陋的行...

I updated my Nexus 7 to Android 5.1 some minutes ago (was Running 5.0 before) and stopped seeing this issue in this new version. As the appearance of the FastScroll indicator also changed in 5.1, I assume that google fixed this issue or at least commented out those ugly lines that spammed the console...

75516 和放大器; 82461 仍然未能解决的个案,但我想那些参考同样的问题,这是目前解决了5.1。

75516 & 82461 are still 'unresolved', but I guess that those refer to the same issue, that's now resolved in 5.1.

这篇关于安卓:requestLayout()不正确地称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆