Android: requestLayout() improperly called

requestlayout() improperly called by scrollview container
requestlayoutduringlayout is already in process

The following error occurs when I attempt to inflate a layout within a ListView:

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

I am attempting to inflate a layout within a ListView as follows:

@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"/>

I have looked into similar questions, and no solutions found seem to work Question 1, Question 2, Question 3.

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

UPDATE

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>

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

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

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() improperly called by android.widget.TextView{...} during layout: running second layout pass

message in your console.

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).

Cheers

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

EDIT May 12 2015:

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 are still 'unresolved', but I guess that those refer to the same issue, that's now resolved in 5.1.

RequestLayout() improperly called · Issue #371 · roughike , I've got these warnings whenever the Tab Bar activity is launched. W/View: requestLayout() improperly called by android.support.v7.widget. 06-11 18:46:20.770 4961-4961/com.prjctt.allan.newfinance W/View﹕ requestLayout() improperly called by com.prjctt.allan.newfinance.ExpandedListView{225d8596 VFED..C. .F.ID 0,86-316,209 #102000a android:id/list} during layout: running second layout pass 06-11 18:46:20.795 4961-4961/com.prjctt.allan.newfinance W/View﹕ requestLayout

The problem is that while the method getView() of your adapter is displaying your layout some other code is trying to access this view to display it, resulting in a collision.

Note that some methods, that maybe you don't take care of (like setScale(), setTypeFace()) indeed call requestLayout(), so it would be interesting what you are doing after your inflate statement.

requestLayout() improperly called by , requestLayout() improperly called by android.widget.TextView requestLayout() improperly called by crc64ee486da937c010f4.LabelRenderer  If a new item is added to the ObservableCollection bound to the listView, the "requestLayout () improperly called by.. " message shows up. Also it affects the actual drawing of the list view after scrolling up. Reverting back to XF 2.5.1.527436 resolved the problem Angelru9

For me this issue was occurring upon a setLayoutParams() call. The solution was posting a runnable on the looper as stated here

requestLayout() improperly called by, I get the following error: 08-23 20:58:24.574 W/View ( 4164): requestLayout() improperly called by md5b60ffeb829f638581ab2bb9b1a7f4f3f. requestLayout () improperly called. I'm getting this warning spammed in my console. The only info I can find is most people get it when they have fast scroll enabled in a listview. I'm not using any listviews. It says its being improperly called by CollapsingToolbarLayout, AppCompatTextView, Toolbar, and sometimes AppBarLayout.

I fixed this issue by disabling fastScroll on the ListView in the XML.

<ListView
    android:id="@+id/mListview"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"

    android:fastScrollEnabled="false"
/>

requestLayout() improperly called, I upgraded from XF 2.5.0.1222 to 3.1 and now I get the error repeatedly on Android, several per second. This is even when nothing is happening on 06-27 17:04:14.986 W/View (19973): requestLayout() improperly called by  Description Getting infinite console messages when adding items to an ObservableCollection that is tied to a ListView Steps to Reproduce Create a ListView and have its ItemSource set to an ObservableCollection.

This might happen if you are using some 3rd party extension of ListView. Replace that with standard ListView and check if it still throws the error.

I had similar problem. Please check Android layout: running second layout pass and my answer.

requestLayout() improperly called by SfNumericTextBox on Android , requestLayout() improperly called by android.widget.LinearLayout{547fe5a V.E​ ID 0,0-0,0} during layout: running second layout pass. This break the repeating loop "08-24 14:26:32.466: W/View(4327): requestLayout() improperly called by ". I have no idea if I break anything else but it works for me so fare. I am interested if this helps any where else or if I do a big mistake

requestLayout() improperly called, requestLayout() improperly called by android.widget.TextView{} during layout: running second layout pass. I am attempting to inflate a layout within a ListView  requestLayout () improperly called by android.widget.TextView {…} during layout: running second layout pass message in your console. 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.

Android: requestLayout() improperly called, requestLayout() improperly called by android.widget. here i'm using frame layout when click ,the login linearlayout called ,here when try clikc  Hello. I have this issue that infinitely print in log: W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatTextView{b2debd V.ED..C.. .. 36,47-348,120 #7f090275 app:id/tvTitle} during second layout pass:

requestLayout() improperly called by android.widget.LinearLayout , console on Android applications running Forms 2.3.4. [View] requestLayout() improperly called by md5b60ffeb829f638581ab2bb9b1a7f4f3f.

Comments
  • What else happens in the ... inside first if block?
  • It reuses the Views through a ViewHolder
  • Take a look at this. stackoverflow.com/questions/22078961/…
  • Spent the last hour trying to fix this. Turned off fast scroll and the messages are gone. At least I know it's not something I did. Thanks for the info.
  • is there any solution to remove this log ?
  • I'm trying to persist my ImageView size in onSaveInstanceState, and that's when this error showed up and crashed my app. Not sure how to fix it, but this answer is more descriptive than just "it's a bug", so thanks for that. So, for me, it was not a scrolling issue.
  • I'm probably having the same problem, but that link is broken. EDIT: resolved with the following: imageView.post(new Runnable() { @Override public void run() { imageView.setLayoutParams(params); }});
  • I don't think that this is a solution if you want to use fast scroll.
  • Thanks for the suggestion! Unfortunately this did not work, please see my update
  • any luck for this? I am facing the same issue :(
  • Unfortunately no - because it is just a warning I will probably end up regretfully ignoring it