android - FloatingActionButton Behavior call back not working in DrawerLayout -
i have drawerlayout coordinator layout hosted main content. when create snackbar snackbar.make method, fab hosted in coordinator layout refuses animate.
i find odd, because i've used same fab in coordinator layouts aren't wrapped in drawerlayout , animates fine, leading believe drawerlayout somehow blocking call back.
i've tried making coordinatorlayout top level view, wrapping drawerlayout, doesn't work. i'm going attempt forking floatingactionbutton behavior class , making updatefabtranslationforsnackbar method public can call myself. i'd rather not this, ideas appreciated.
for both activities, snackbar.make call called fragment added dynamically relativelayout id "container". view passed call coordinatorlayout in activity xml id "coordinator_layout".
again, works should in first xml, not in second.
this default xml other activities, fab animates fine here:
<android.support.design.widget.coordinatorlayout android:id="@+id/coordinator_layout" android:name="com.app.mobile.app.ui.businessactivityfragment" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <progressbar android:id="@+id/progress_bar" style="?android:attr/progressbarstylelarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginbottom="8dp" /> <relativelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> <imageview android:id="@+id/background" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:scaletype="centercrop" android:src="@drawable/bg_sign_up" android:visibility="invisible" /> <view android:id="@+id/background_mask" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:background="@color/black_40" android:visibility="invisible" /> </relativelayout> <include android:id="@+id/action_bar" layout="@layout/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/abc_action_bar_default_height_material" android:layout_gravity="top" /> <android.support.design.widget.floatingactionbutton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" /> <progressbar android:id="@+id/load_more" style="?android:attr/progressbarstylehorizontal" android:layout_width="match_parent" android:layout_height="@dimen/half_margin" android:layout_gravity="bottom" android:indeterminate="true" android:visibility="gone" />
this xml main activity fab refuses animate:
<android.support.v4.widget.drawerlayout android:id="@+id/navigation_layout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.app.mobile.app.ui.homeactivity"> <!-- main content view, view below consumes entire space available using match_parent in both dimensions. --> <android.support.design.widget.coordinatorlayout android:id="@+id/coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:animatelayoutchanges="true"> <!-- toolbar last item in framelayout cause overlay --> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:animatelayoutchanges="true" android:orientation="vertical"> <progressbar android:id="@+id/home_progress" style="?android:attr/progressbarstylelarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:layout_gravity="center" android:layout_marginbottom="8dp" /> <relativelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" /> </relativelayout> <include android:id="@+id/action_bar" layout="@layout/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/abc_action_bar_default_height_material" android:layout_gravity="top" /> <android.support.design.widget.floatingactionbutton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" /> <progressbar android:id="@+id/load_more" style="?android:attr/progressbarstylehorizontal" android:layout_width="match_parent" android:layout_height="@dimen/half_margin" android:layout_gravity="bottom" android:indeterminate="true" android:visibility="gone" /> </android.support.design.widget.coordinatorlayout> <!-- android:layout_gravity="start" tells drawerlayout treat sliding drawer on left side left-to-right languages , on right side right-to-left languages. if you're not building against api 17 or higher, use android:layout_gravity="left" instead. --> <!-- drawer given fixed width in dp , extends full height of container. --> <fragment android:id="@+id/navigation_drawer" android:name="com.app.mobile.app.ui.navigationdrawerfragment" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="start" android:tag="navigation_drawer_tag" tools:layout="@layout/fragment_navigation_drawer" />
make sure passing right view snackbar.make()
method. per docs,
snackbar try , find parent view hold snackbar's view value given view. snackbar walk view tree trying find suitable parent, defined coordinatorlayout or window decor's content view, whichever comes first.
so should pass view inside coordinatorlayout
, snackbar find coordinator first parent available.
Comments
Post a Comment