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 안에 다른보기있을 때를 제외하고는 잘 작동됩니다. 여기

내 레이아웃입니다 :

custom_layout 항목을 터치하고 위쪽으로 이동하면 내가지도 레이아웃을 축소 할 수하지만 여전히 (이 canDrag에서 false를 반환하여 작동)을 스크롤 할 수 있도록하려는
<?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> 

.

그래서 내가

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; 
} 

아직 시도하지 않았으므로 몇 가지 추가 트위크를 만들어야 할 수도 있습니다.