7

ViewPagerフラグメントにRecyclerViewをスクロールするときに、ViewPagerに影響を与える折りたたみエフェクトを使わずに、ツールバーを単独で折りたたむ方法を教えてください。WhatsApp Androidと同様に、コンテンツをプッシュせずにAppBarLayoutをアニメーション化する方法を教えてください。

WhatsApp Androidでは、ツールバーがコンテンツとともに移動しない3つのメインリストのいずれかをスクロールすると、その代わりに独立したアニメーション軸があり、非常に滑らかで、コンテンツビュー。私が上に移動または下に、ほんの少し、RecycleViewは、ツールバーの崩壊アニメーションによって押されていないかどうかを確認することができ、それが独立して動く:

enter image description here

I持ってMainActivityレイアウトで次の階層:

<CoordinatorLayout> 
    <AppBarLayout> 
     <Toolbar/> 
     <TabLayout/> 
    </AppBarLayout> 

    <ViewPager> 
     <!-- Fragments with RecyclerView --> 
    </ViewPager> 

</CoordinatorLayout> 

activity_main.xml

<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|snap|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:clickable="true" 
     app:layout_behavior="ScrollingFABBehavior" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

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

とフラグメントの内容はRecyclerViewです:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="fragments.ConversationsFragment"> 

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

</FrameLayout> 

しかし、私はRecyclerViewをスクロールするとき、私はツールバーを途中停止した場合、代わりのWhatsAppに独立して類似したアニメーションの移動、突然ダウンフラグメントを押し上げたりされています。この例では ​​

それがさらに極端です:

enter image description here

そして、私はSCとスナップを追加しない場合ロールフラグを設定すると、ツールバーは途中で停止したり、スクロールした範囲に応じてフラグメントをプッシュしたりします。 CoordinatorLayoutを使用していることを達成する

app:layout_scrollFlags="scroll|snap|enterAlways" 

任意の方法?もしそうでなければ、どんなポインタでも分かるはずです。

+0

はあなたがこの問題に対する答えを見つけましたか?これは最近私を悩ませています。 – Andrew

+0

@Andrew私はもう問題を心配していませんでしたが、最初にアプリのデザイン全体を終了することになりました。しかし、私はもう一度それをもう一度見ていきます。 – AlfredBaudisch

+0

ネストされたスクロールはここで動作します。参考にしてくださいhttps://github.com/chrisbanes/cheesesquare – GvSharma

答えて

0

使用NestedScrollView同様のWhatsAppを達成するために、

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clipToPadding="false" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

</android.support.v4.widget.NestedScrollView> 
関連する問題