1

私は画像のようなものを投稿しようとしていますが、viewpagerがrecyclerViewでスクロール可能であり、ヘッダーは単純な線形/相対レイアウトであり、これは静的であり、ファブと同じです(スクロールできません)。ワーキング。私は誰かがどのようにAppBarLayoutとCollapsingToolbarLayoutを説明することができますか?

まず

enter image description here

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<include layout="@layout/layout_view_pager" 
    app:layout_collapseMode="parallax" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clipToPadding="true" 
    android:saveEnabled="false" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <RelativeLayout 
       android:id="@+id/header_labels" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/header_height" 
       android:background="@color/brand_green" 
       app:layout_collapseMode="pin" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/actionbar_title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:textColor="@android:color/white" 
        android:textSize="43sp"/> 

       <TextView 
        android:id="@+id/actionbar_balance_label" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:layout_marginTop="5dp"   android:textSize="13sp"/> 
      </RelativeLayout> 

     <android.support.v7.widget.Toolbar 
        android:id="@+id/my_toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        app:layout_collapseMode="pin" 
        app:contentInsetStart="0dp"> 

        <TextView 
         android:id="@+id/chime_sign" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:gravity="center" 
         app:iconFontColor="@android:color/white" 
         app:iconFontSize="26sp"/> 

       </android.support.v7.widget.Toolbar> 

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

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

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:clickable="true" 
    android:src="@drawable/fab_icon_mm" 
    app:elevation="6dp" 
    app:fabSize="normal" 
    app:rippleColor="@color/brand_dark_green" 
    app:pressedTranslationZ="12dp" 
    app:layout_anchor="@id/header_labels" 
    app:layout_anchorGravity="bottom|right|end"/> 

+0

「viewpagerはrecyclerViewでスクロール可能です。」 – Karakuri

+0

はい、recyclerViewのスクロールを開始すると、リストビューのヘッダーのように、viewpagerもcollapsingtoolbarlayout(可能であれば)でスクロールしています – DiegoF

答えて

0

の下に私のレイアウトを掲載

、あなたはどんな効果を示さないであろうRelativeLayoutToolbarの両方のためにpinapp:layout_collapseModeを設定しました。 app:layout_collapseModeを任意のビューに固定しても、スクロール時のビューの高さは変更されません。スクロール時にビューの高さを変更するには、app:layout_collapseModeparallaxに設定する必要があります。

次に、AppBarLayoutに指定された高さを設定します。 WRAP_CONTENTの設定は正しく動作しません。 180dpのような特定の寸法を設定する必要があります。

第3に、あなたの質問によると、RecyclerViewでビューポートをスクロール可能にしたかったのです。あなたのコードは意図した通りに動作しません。 ViewPagerRecyclerViewでスクロールできるようにするには、RecyclerViewをxmlコードから削除し、別のxmlコードファイルに追加する必要があります。次に、Fragmentまたは2つ(必要に応じて)を作成し、FragmentViewPagerに追加し、そこでRecyclerViewをインスタンス化する必要があります。このFragmentは、RecyclerViewのデータを膨張させる責任も負います。

+0

'AppBarLayout'の高さに' wrap_content'を使うことに何も問題はありません。私はアプリでそれをやっています。彼が断片をまったく使用しないという要件もあります。 「viewpagerがrecyclerViewでスクロール可能である」と言うとき、彼が何を意味するのかは疑問からは分かりません。彼は、ViewPagerがRecyclerViewの最初のアイテムであるかのように行動することを望んでいることを意味する可能性があります。 – Karakuri

関連する問題