我有
CoordinatorLayout
父母,在这个父母里面是布局bottomSheetContainer
,它将包含BottomSheet
,它有BottomSheetBehaviour
附加到它。然后在它上面有两个锚定按钮,它们基本上悬停在BottomSheet
.
我想要实现的是,如果我向下滑动
Bottomsheet
并缓慢拖动它(它的高度会随着我拖动它而动态变化)那些锚定在BottomSheet
顶部的按钮将沿着顶部边缘移动。
目前,只有当
Bottomsheet
完全消失并且BottomSheet
为空时,这些按钮才会向下移动。
这是我的布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:clipChildren="false"
android:animateLayoutChanges="true"
android:animationCache="true">
<LinearLayout
android:id="@+id/map_mode_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_medium"
android:layout_gravity="top"
android:translationZ="@dimen/hover_parent_elevation"
android:elevation="@dimen/hover_parent_elevation"
android:translationY="@dimen/hover_size"
app:layout_anchor="@id/bottomSheetContainer"
app:layout_anchorGravity="start"
android:orientation="horizontal">
</LinearLayout>
<ImageButton
android:id="@+id/but_location"
android:layout_width="@dimen/tab_button_height"
android:layout_height="@dimen/tab_button_height"
android:layout_margin="@dimen/padding_medium"
app:layout_anchor="@id/bottomSheetContainer"
app:layout_anchorGravity="end"
android:layout_gravity="top"
android:translationZ="@dimen/hover_parent_elevation"
android:elevation="@dimen/hover_parent_elevation"
android:translationY="@dimen/hover_size"
android:src="@drawable/location_icon"
style="@style/button_circle"
app:tint="@color/primary" />
<include
android:id="@+id/bottomSheetContainer"
layout="@layout/bottom_sheet_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:layout_gravity="bottom" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
bottom_sheet_container
:
<FrameLayout
android:id="@+id/bottomSheetContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这是将添加到
bottomSheetContainer
中的Bottomsheet布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants"
android:clipChildren="false"
android:clipToPadding="false"
android:clickable="true"
android:focusable="true">
<include android:id="@+id/baseLayout" layout="@layout/bottom_sheet_base_layout" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
和
bottom_sheet_base_layout
是bottom_sheet内容(实际LinearLayout
具有用于滚动的bottomsheet行为)