RequestLayout () is incorrectly called

I get this warning from spam in my console. The only information I can find is most people get it when they have a quick scroll included in the listview. I do not use lists. He says that he is incorrectly called CollapsingToolbarLayout, AppCompatTextView, a toolbar, and sometimes AppBarLayout. This happens whenever I quickly โ€œdropโ€ my nested scroll up and down to collapse and expand the toolbar.

Logs:

06-30 22:18:42.622 19090-19090/? I/art: Not late-enabling -Xcheck:jni (already on) 06-30 22:18:43.153 19090-19090/joebruckner.lastpick.debug D/MovieShuffleActivity: false, true, false 06-30 22:18:43.205 19090-19126/joebruckner.lastpick.debug D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true [ 06-30 22:18:43.267 19090:19126 D/ ] HostConnection::get() New Host Connection established 0xea95fdb0, tid 19126 06-30 22:18:43.287 19090-19126/joebruckner.lastpick.debug I/OpenGLRenderer: Initialized EGL, version 1.4 06-30 22:18:43.806 19090-19090/joebruckner.lastpick.debug D/MovieShuffleActivity: false, true, true 06-30 22:28:49.264 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{5041bd9 V.ED..... ......ID 0,0-1080,525 #7f0d0074 app:id/collapsingToolbar} during layout: running second layout pass 06-30 22:28:49.264 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.v7.widget.Toolbar{612299e VE..... ......ID 0,291-1080,438 #7f0d0069 app:id/toolbar} during layout: running second layout pass 06-30 22:28:49.277 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{5041bd9 V.ED..... ........ 0,0-1080,525 #7f0d0074 app:id/collapsingToolbar} during second layout pass: posting in next frame 06-30 22:28:49.456 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{5041bd9 V.ED..... ......ID 0,0-1080,525 #7f0d0074 app:id/collapsingToolbar} during layout: running second layout pass 06-30 22:28:49.456 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.v7.widget.Toolbar{612299e VE..... ......ID 0,197-1080,344 #7f0d0069 app:id/toolbar} during layout: running second layout pass 06-30 22:28:49.475 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{5041bd9 V.ED..... ........ 0,0-1080,525 #7f0d0074 app:id/collapsingToolbar} during second layout pass: posting in next frame 06-30 22:28:49.696 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{5041bd9 V.ED..... ......ID 0,0-1080,525 #7f0d0074 app:id/collapsingToolbar} during layout: running second layout pass 06-30 22:28:49.696 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.v7.widget.Toolbar{612299e VE..... ......ID 0,0-1080,147 #7f0d0069 app:id/toolbar} during layout: running second layout pass 06-30 22:28:49.741 19090-19090/joebruckner.lastpick.debug W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{5041bd9 V.ED..... ........ 0,0-1080,525 #7f0d0074 app:id/collapsingToolbar} during second layout pass: posting in next frame 

Xml:

 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/appBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsingToolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary" app:titleEnabled="false" android:fitsSystemWindows="true"> <ImageView android:id="@+id/backdrop" android:layout_width="match_parent" android:layout_height="200dp" android:contentDescription="@string/backdrop" android:scaleType="fitXY" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/appBar" app:layout_behavior="@string/scrolling_view" app:behavior_overlapTop="80dp" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:src="@drawable/ic_dice_three_48dp" app:layout_anchor="@+id/frame" app:layout_anchorGravity="bottom|end" /> </android.support.design.widget.CoordinatorLayout> 
+6
source share
5 answers

This can happen when your adapterโ€™s getView () method displays your layout, and other code tries to access that view in order to display it, resulting in a collision. Please check.

+1
source

Are you setting any AppBarLayout.OnOffsetChangedListener? If so, it could be due to attribution of layout parameters or any given value of this type in your listener.

If this is your situation, set the layout attributes to the main thread.

 appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { //post message back on main thread if you need to modify any views } }); 
+1
source

This message is only a warning that some view has already requested a layout, and when other views (in your case Toolbar and CollapsingToolbarLayout ) already request a layout during the layout phase.

In some cases, this leads to performance flaws. You must determine:

  • Do you have a custom View / ViewGroup that calls requestLayout() while scrolling? Do you have other code that calls requestLayout() ? Do you have any code that changes the hierarchy of the detailed hierarchy of the layout, for example, to make the view GONE ?

  • When does this happen? Is it only at the beginning, shortly before all the views are laid out?

You have suspicious submissions called requestLayout() inappropriately, you need to find who, when and why previously makes your layout restructured.

+1
source

Setting permission to CollapsingToolbarLayout instead of the toolbar helped me solve this problem

 collapsingToolbarLayout.setTitle(title); 

instead

 toolbar.setTitle(title); 
0
source

My solution is to forward offset changes only when they are different

  appbar.addOnOffsetChangedListener(object : AppBarLayout.OnOffsetChangedListener { var lastOffset = -1 override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) { if (lastOffset == verticalOffset) return lastOffset = verticalOffset val percentage = Math.abs(verticalOffset).toFloat() / (appBarLayout?.totalScrollRange?.toFloat() ?: 1f) toolbarAnimation.animate(percentage) } }) 
0
source

All Articles