0

我切換到CoordinatorLayout/AppBarLayout主要是爲了利用app:layout_scrollFlags="scroll|enterAlways"(當向上滾動時從頂部查看)。我使用的RecyclerView沒有NestedScrollLayout作爲第二個防止回收視圖和加載後很多項目開始滯後。更改AppBarLayout高度使得列表下面「跳」急劇

「peeking」視圖是AppBarLayout,它在被點擊時調整大小以顯示/隱藏過濾器選項。除了在調整AppBarLayout(通過設置子視圖可見性)時,除了調整AppBarLayout的大小之外,一切都按預期工作,但似乎整個佈局正在呈現,僅僅一小會兒RecyclerView就會「跳躍」到頂部,然後回到預期行爲。這非常非常快但非常煩人。當被替換爲LinearLayout時,它不會發生,但顯然該視圖不會偷看。

我的佈局:

<?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/fragment_notifications" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:animateLayoutChanges="true"> 

    <android.support.design.widget.AppBarLayout android:id="@+id/fragment_notifications_filter_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     android:animateLayoutChanges="true"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:animateLayoutChanges="true" 
      app:layout_scrollFlags="scroll|enterAlways"> 

      <!--Two example views with different heights, of which only one is visible at a time --> 
      <ImageView android:id="@+id/view1" 
       android:layout_width="match_parent" 
       android:layout_height="68dp" 
       android:src="@drawable/ic_launcher"/> 

      <ImageView android:id="@+id/view2" 
       android:layout_width="match_parent" 
       android:layout_height="44dp" 
       android:src="@drawable/ic_launcher"/> 
      ... 
     </RelativeLayout> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/fragment_notifications_refresh" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/fragment_notifications_notifications" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:scrollbars="vertical" /> 

     </FrameLayout> 
    </android.support.v4.widget.SwipeRefreshLayout> 

</android.support.design.widget.CoordinatorLayout> 

的Java代碼非常簡單;只是設置裏面的視圖的可見性AppBarLayout

someViewInsideAppBarLayout.setVisibility(visible ? View.VISIBLE : View.GONE); 

任何想法如何處理這個?謝謝!

回答

0

我必須在具有應用程序滾動行爲的ViewGroup中啓用類型LayoutTransition.CHANGING(默認情況下禁用)的轉換(在我的情況下爲SwipeRefreshLayout)。

LayoutTransition layoutTransition = swipeRefreshLayout.getLayoutTransition(); 
layoutTransition.enableTransitionType(LayoutTransition.CHANGING); 

後來我面臨着被更改爲0(原300)的LayoutTransition.CHANGE_DISAPPEARING值消失期(縣)的家長解決了額外的奇動畫行爲:

relativeLayout.getLayoutTransition().setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0); 
appBar.getLayoutTransition().setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0); 
coordinatorLayout.getLayoutTransition().setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);