2

我試圖描述hereCoordinatorLayout.Behavior不會被調用

程序編譯和運行,但協調的佈局行爲函數永遠不會被調用,因此小吃吧覆蓋的FAB實現自定義FAB菜單上協調的佈局行爲菜單。

關於它的唯一的其他問題是here但提供的解決方案不是我的問題。

這裏是XML:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.getbase.floatingactionbutton.FloatingActionsMenu 
     android:id="@+id/fab_host" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end|bottom" 
     android:layout_margin="@dimen/fab_margin" 
     app:layout_behavior="com.companionfree.quizinator.couple.shared.FloatingActionMenuBehavior" 
     fab:fab_icon="@drawable/ic_add_white_24dp" 
     fab:fab_addButtonColorNormal="@color/colorAccent"> 


     <com.getbase.floatingactionbutton.FloatingActionButton 
      android:id="@+id/fab_host_bluetooth" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      fab:fab_colorNormal="@color/colorAccent" 
      fab:fab_icon="@drawable/ic_bluetooth_white_24dp"/> 


     <com.getbase.floatingactionbutton.FloatingActionButton 
      android:id="@+id/fab_host_nearby" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      fab:fab_colorNormal="@color/colorAccent" 
      fab:fab_icon="@drawable/ic_signal_wifi_4_bar_white_24dp"/> 


    </com.getbase.floatingactionbutton.FloatingActionsMenu> 
</android.support.design.widget.CoordinatorLayout> 

這裏是我的CoordinatorLayout.Behavior類:

public class FloatingActionMenuBehavior extends CoordinatorLayout.Behavior<FloatingActionsMenu> { 

    public FloatingActionMenuBehavior(Context context, AttributeSet attrs) {} 

    @Override 
    public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionsMenu child, View dependency) { 
    return dependency instanceof Snackbar.SnackbarLayout; 
    } 

    @Override 
    public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionsMenu child, View dependency) { 
     float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); 
    child.setTranslationY(translationY); 
    return true; 
    } 
} 

有沒有錯誤,小吃吧顯示器,它只是覆蓋的FAB菜單...我似乎無法弄清楚錯誤在哪裏。

+0

這有你的問題的答案:http://stackoverflow.com/questions/32802886/move-cardview-on-snackbar-co-ordinator-layout –

+0

@Rohit_Ramkumar我回顧了答案問題並沒有發現有用的東西也許你可以解釋我錯過了什麼? – easycheese

+0

好的。您可以在顯示快餐欄時發佈代碼嗎?我想看看你如何製作小吃店並展示它。 –

回答

3

對於推動FAB的小吃店,您需要將FloatingActionsMenu視圖傳遞給snackBar,同時製作它。

Snackbar.make(FloatingActionsMenuVIEWINSTANCEHERE, mErrorMessage, Snackbar.LENGTH_LONG); 

然後調用show()方法。這應該解決問題

+0

是的,就是這樣。我使用getView()在片段中調用它。我在這裏單獨找到它:https://guides.codepath.com/android/Displaying-the-Snackbar,但我會給你勝利:) – easycheese