android – requestLayout()调用不当

我在我的控制台中收到此警告.我能找到的唯一信息是大多数人在列表视图中启用快速滚动时获得它.我没有使用任何列表视图.它说它被CollapsingToolbarLayout,AppCompatTextView,Toolbar和AppBarLayout不正确地调用.每当我快速“推动”我的嵌套滚动视图上下折叠并展开工具栏时,就会发生这种情况.

日志:

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
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 V.E...... ......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,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,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 V.E...... ......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,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,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 V.E...... ......ID 0,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,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>

解决方法

此消息仅用作某个视图已请求布局的警告以及其他视图(在您的情况下为Toolbar和CollapsingToolbarLayout)已在布局阶段请求布局的警告.

在某些情况下,这会导致性能缺陷.你应该确定:

>你有一些自定义View / ViewGroup在滚动期间调用requestLayout()吗?你有其他调用requestLayout()的代码吗?您是否有任何代码可以进行广泛的布局子级更改,例如使视图GONE?
>这是什么时候发生的?只是在开始时,就在所有观点布局之前?

您有可疑的视图,称为requestLayout()不正确,您需要找到谁,何时以及为什么以前进行布局重组.

相关文章

以下为个人理解,如错请评 CE: 凭据加密 (CE) 存储空间, 实际路径/data/user_ce/ DE: 设备加密 (DE) 存...
转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144 用EventLog.writeEvent打的日志(或...
事件分发机制详解 一、基础知识介绍 1、经常用的事件有:MotionEvent.ACTION_DOWN,MotionEvent.ACTION...
又是好久没有写博客了,一直都比较忙,最近终于有时间沉淀和整理一下最近学到和解决的一些问题。 最近进...
Android性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向...
android的开源库是用来在android上显示gif图片的。我在网上查了一下,大家说这个框架写的不错,加载大的...