2016-07-09 8 views
0

ここに私がしたいことがあります:CollapsingToolbarLayoutにマップを表示するには、マップの下に2つのコントロールを含むカスタムレイアウトを配置する必要があります。その下にはRecyclerViewがあります。カスタムレイアウトをRecyclerViewと同様にスクロールできるようにしたいが、RecyclerViewがスクロールしている間にカスタムレイアウトを一番上に修正したい。 は、ここで私が達成したいもののイメージです(灰色=マップを、赤=カスタムレイアウト;緑= RecyclerView): enter image description hereCollapsingToolbarLayout:上にカスタムレイアウトを修正します

ここで私がこれまで持っているものです。カスタムレイアウト(赤色)が画面の上部に達するとスクロールを停止しない点を除いて、うまく動作します。

<?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" 
    xmlns:mapbox="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="400dp" 
     android:orientation="vertical" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <com.mapbox.mapboxsdk.maps.MapView 
       android:id="@+id/map_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_collapseMode="parallax" 
       mapbox:zoom="12" 
       mapbox:style_url="@string/style_light" 
       mapbox:access_token="@string/access_token"> 
      </com.mapbox.mapboxsdk.maps.MapView> 

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

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

    <LinearLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <include layout="@layout/current_activity"></include> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/activity_list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="16dp"> 

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

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

この動作を達成する最も簡単な方法は何ですか?

答えて

0

答えは実際にはかなり簡単です。カスタムレイアウトをAppBarLayoutに移動するだけでした。

<?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" 
    xmlns:mapbox="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <com.mapbox.mapboxsdk.maps.MapView 
       android:id="@+id/map_view" 
       android:layout_width="match_parent" 
       android:layout_height="400dp" 
       app:layout_collapseMode="parallax" 
       mapbox:zoom="12" 
       mapbox:style_url="@string/style_light" 
       mapbox:access_token="@string/access_token"> 
      </com.mapbox.mapboxsdk.maps.MapView> 

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

     <include layout="@layout/current_activity" 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      android:background="?attr/colorAccent"/> 
    </android.support.design.widget.AppBarLayout> 

    <LinearLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/activity_list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="16dp"> 

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

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

アプリ追加:

はここレイアウトだlayout_collapseMode =「ピン」は、あなたの赤いビューのこの属性は、画面の上部に固定します。 これで問題が解決する場合があります

関連する問題