[英]Floating Action Button position
我在布局的底部有一個“片段”,當顯示時它與我的FAB重疊。
因此,如何使FAB依賴於此片段(顯示片段時抬起FAB,就像顯示Snackbar時一樣)?
FAB
和Snackbar
之間的行為是將CoordinatorLayout
作為兩個視圖的直接父級的結果。 協調器布局可處理此動畫效果。
協調器布局用作與一個或多個子視圖進行特定交互的容器。
通過為CoordinatorLayout的子視圖指定“行為”,您可以在單個父視圖中提供許多不同的交互,並且這些視圖也可以彼此交互。
參考: 協調器布局| Android開發人員
因此,您持有該片段的視圖需要為其提供一個Behaviour
實現。 這將定義您的視圖如何與其他視圖交互。
查看本指南 ,了解如何為CoordinatorLayout
創建Behaviours
。
對於FloatingActionButton
此行為已在其類中定義。 在此處檢查源。
我找到了解決方案。 這是我的布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/mediaPlayerControlBar">
<RelativeLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
app:layout_behavior="com.unimusic.ScrollAwareFABBehavior"
app:fabSize="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_search_white_24dp"
android:id="@+id/fab"
android:layout_margin="16dp"
app:elevation="4dp"/>
</android.support.design.widget.CoordinatorLayout>
<fragment android:name="com.unimusic.mediaPlayerControlBar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="@+id/mediaPlayerControlBar"
android:layout_gravity="bottom"
app:layout_anchor="@id/snackbarPosition"
app:layout_anchorGravity="bottom"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
基本上,我已經將相對布局作為根組件而不是CoordinatorLayout。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.