2

AppBarLayoutにスクロール可能なビューが含まれている場合、このビューをスクロールするとAppBarLayoutのスクロール動作が妨げられるという既知のバグです。 SO上AppBarLayout選択したビューでドラッグを無効にする

多くの答えは次のソリューション

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); 
AppBarLayout.Behavior behavior = new AppBarLayout.Behavior(); 
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() { 
     @Override 
     public boolean canDrag(AppBarLayout appBarLayout) { 
      return false; 
     } 
}); 
params.setBehavior(behavior); 

を提案し、これはAppBarLayoutをスクロールすることができるはず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"> 

     <fragment 
     android:id="@+id/mapFragment" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_collapseMode="parallax" /> 

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

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

私はcustom_layout項目をタッチして上方に移動されたときに地図をスクロール(これはcanDragからfalseを返すことによって動作します)が、それでもレイアウトを折りたたむことができることができるようにしたいです。

だから私は、これを実現する方法を

behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() { 
      @Override 
      public boolean canDrag(AppBarLayout appBarLayout) { 
       if(mapIsScrolled) 
       return false; 
       else 
       return true; 
      } 
    }); 

のようなものの任意のアイデアが必要ですか? AppBarLayoutのうち

+0

ねえ、どうやってこの問題を解決しましたか? – Anupriya

答えて

0

移動これを:

<include layout="@layout/custom_layout" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:background="?attr/colorAccent"/> 

それともあなたが本当にあなたのレイアウトは、上崩壊部分にあることが必要な場合は、レイアウトにタッチリスナーを追加(またはフォーカスリスナーを試してみてください)。

private boolean handleTouchEvent(MotionEvent event) { 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
      case MotionEvent.ACTION_MOVE: 
       canCollapse = true; 
    } 
    return false; 
} 


public boolean canDrag(AppBarLayout appBarLayout) { 
    if(canCollapse) 
     return true; 
    else 
     return false; 
} 

まだ試したことがないので、追加のツイークを作成する必要があります。

関連する問題