0

내 프로젝트 중 하나는 일반적인 동작 클래스를 사용하여 완벽하게 작동하는 fab 버튼을 숨기거나 표시하는 것입니다. 이제는 레이아웃 요구 사항을 변경해야합니다. 스크롤 업의 show fab은 작동하지 않습니다.FloatingActionButton은 FrameLayout 내의 RecyclerView와 관련된 문제를 인식합니다.

CoordinatorLayout 설정은 표준이며 그 안에 조각을로드하는 ViewPager가 포함되어 있습니다. Fragment 레이아웃을 변경하여 fab show 동작이 더 이상 올바르게 작동하지 않게되었습니다.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:id="@+id/emptyStateView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:translationY="@dimen/home_empty_state_y_offset"> 

     <ImageView 
      android:id="@+id/emptyStateImage" 
      android:layout_width="wrap_content" 
      android:layout_height="160dp" 
      android:layout_centerInParent="true" 
      android:src="@drawable/home_empty_state_animation" /> 

    </RelativeLayout> 

    <SwipeRefreshLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RecyclerView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/filterMenu" 
      android:clipToPadding="false" /> 
    </SwipeRefreshLayout> 
</FrameLayout> 

그것은처럼 보인다 : 여기


<SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RecyclerView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/filterMenu" 
     android:clipToPadding="false" /> 
</SwipeRefreshLayout> 
이 작동하지 않는 새로운 조각 레이아웃입니다 : 여기

은 원래 작업 조각 레이아웃입니다 추가 된 FrameLayout이 이러한 문제를 일으키고 있지만 왜 그럴까? 이것은 설계상의 문제입니까? 또는 나는 무엇인가 놓치고 있냐?

답변

2

잘 해결되었습니다. FloatingActionButtonCoordinatorLayout에는 몇 가지 유형의 버그 또는 이상한 것이 있습니다.

FloatingActionButton.hide()은 버튼 가시성을 GONE으로 만듭니다. 이는 CoordinatorLayoutFloatingActionButton에 대한 추가 이벤트를 무시하게 만듭니다. 이것이 스크롤을 내려도 다시 버튼이 표시되지 않는 이유입니다.

FloatingActionButton.hide()을 호출 한 후 FloatingActionButton의 가시성이 INVISIBLE으로 설정되었는지 확인하는 것이 솔루션입니다.

@Override 
public void onNestedScroll(CoordinatorLayout coordinatorLayout, final FloatingActionButton child, 
          View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { 
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, 
      dyUnconsumed); 

    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) 
    { 
     // This fixes odd issue where fab doesn't show when scrolling down. Seems like the fab 
     // is being set as GONE when hidden. This causes the events on this view to be ignored 
     // by the CoordinatorLayout. 
     child.hide(new FloatingActionButton.OnVisibilityChangedListener() { 
      @Override 
      public void onShown(FloatingActionButton fab) { 
       super.onShown(fab); 
      } 

      @Override 
      public void onHidden(FloatingActionButton fab) { 
       super.onHidden(fab); 


       child.setVisibility(View.INVISIBLE); 
      } 
     }); 
    } 
    else if (dyConsumed <= 0 && child.getVisibility() != View.VISIBLE) 
    { 
     child.show(); 
    } 
} 
+0

미친 문제 ... 공유해 주셔서 감사합니다! –

0

버전 25.1.0의 업데이트 지원 라이브러리 이후에 동일한 문제가있었습니다. 비헤이비어 클래스에서 뷰 가시성을 GONE으로 설정하면 해당 뷰가 무시됩니다. 가능한 솔루션은 지원 라이브러리를 다운 그레이드하거나 행동 클래스를 업데이트하는 것입니다. GONE 대신보기 INVISIBLE을 만듭니다.

+0

잘 모르겠습니까? 문제는 어떻게 든 추가 된 FrameLayout이 스크롤하는 변경 사항을보고하지 않기 때문에 Behavior 클래스가 Fab 버튼을 올바르게 숨기거나 표시 할 수 있습니다. – Jona