0

私のプロジェクトの1つは、共通の動作クラスを使用して完全なファクトボタンを表示/非表示にしています。今、いくつかのレイアウト要件の変更には、スクロール上のショーファブは動作していません。FloatingActionButtonは、FrameLayout内のRecyclerViewで問題を認識します

CoordinatorLayoutの設定は標準で、そこにフラグメントを読み込むViewPagerが含まれています。フラグメントレイアウトの変更により、ファブショーの動作が正しく機能しなくなりました。ここで


は、元の作業フラグメントレイアウトです:

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

ここでは動作しません新しいフラグメントレイアウトです:

<?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> 

それはのように思えます追加された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

関連する問題