6

我在控制檯中收到垃圾郵件警告。我能找到的唯一信息是大多數人在列表視圖中啓用快速滾動時才能獲得它。我沒有使用任何列表視圖。它說它被CollapsingToolbarLayout,AppCompatTextView,工具欄和有時候AppBarLayout不恰當地調用。每當我快速'上下'滾動我的嵌套滾動視圖來摺疊和展開工具欄時,就會發生這種情況。requestLayout()被錯誤地調用

日誌:

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

您能否添加一些日誌以供參考?另外,您是否在使用collasingtoolbar與Activity相關的任何代碼中手動調用requestLayout? – Submersed

+0

我幾次扔掉工具欄中的日誌。不,我不會在任何地方調用它。 – Joe

+0

你能發佈你的XML嗎? – Submersed

回答

1

當你的適配器的方法getView()顯示的是你的佈局,而其他一些代碼試圖訪問該視圖中顯示它可能發生它會導致碰撞。 請檢查。

+0

我在應用程序的這一部分沒有任何適配器 – Joe

1

你是否設置了任何AppBarLayout.OnOffsetChangedListener?如果是這樣,這可能是由於佈局參​​數屬性或您的偵聽器中此類型的任何設置值造成的。

如果這是你的情況,設置在主線程

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

這是錯誤的,您每次調用此方法時都會創建'Handler',並且這個方法被稱爲ALOOOOOOT次。 –

+0

我同意@NikolaDespotoski。從答案中刪除處理程序創建。 – Linox83

0

此消息僅作爲一些觀點已要求佈局和警告當另一個觀點(在你的情況Toolbar和佈局屬性CollapsingToolbarLayout)已經在佈局階段請求佈局。

在某些情況下,這會導致性能缺陷。你應該確定:

  1. 你有一些自定義View/ViewGroup是在滾動過程中調用requestLayout()?你有其他的代碼調用requestLayout()嗎?你有沒有廣泛的佈局子級別更改的代碼,如查看GONE

  2. 這是什麼時候發生的?僅僅在開始之前,就在所有的觀點被佈置之前?

你有懷疑的觀點,即所謂的requestLayout()不當,你需要找到誰,何時,爲什麼以前做你的佈局重組。

0

設置標題CollapsingToolbarLayout而不是工具欄幫助我解決這個問題

collapsingToolbarLayout.setTitle(title); 

,而不是

toolbar.setTitle(title); 
0

我的解決辦法是隻向前偏移的變化時,它們之間的區別

 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) 
     } 
    }) 
相關問題