我想使用 Bottom-sheet来自支持库和两个 float 操作按钮 (FABS),如图所示。关键是我还希望两个 FABS 与底板一起移动,如图 1 和 2。 我必须使用什么基本布局以及如何使 FABS 粘在底纸上?
更新
<LinearLayout
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"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- my context here -->
</LinearLayout>
<!-- bottomsheet -->
<FrameLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
app:behavior_hideable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<include layout="@layout/navigation_info" />
</FrameLayout>
<!-- FABS -->
<!-- wrap to primary fab to extend the height -->
<LinearLayout
android:id="@+id/primary_wrap"
android:layout_width="wrap_content"
android:layout_height="88dp"
app:layout_anchor="@id/bottom_sheet"
app:layout_anchorGravity="top|end">
<android.support.design.widget.FloatingActionButton
android:id="@+id/primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_delete"/>
</LinearLayout>
<!-- Pin secondary fab in the top of the extended primary -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@+id/primary_wrap"
app:layout_anchorGravity="top|end"/>
</android.support.design.widget.CoordinatorLayout>
基于 Ruan_Lopes回答。
通过这种布局,我的 FABS 可以按我想要的方式工作,但我仍然认为我做得不是很清楚。
我想知道是否可以用更正式的方式来做到这一点。
最佳答案
您是否尝试过使用 BottomSheetBehaviour 将 app:layout_insetEdge="bottom"添加到 View 中?像这样的东西,作为 FAB 和 BottomSheetBehaviour View sibling 在 ConstraintLayout 中对我有用:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
app:backgroundTint="@color/white"
app:fabSize="normal"
app:layout_dodgeInsetEdges="bottom"
app:srcCompat="@drawable/icon"
/>
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_insetEdge="bottom"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
/>
关于android - 带有移动 float 操作按钮的 Bottom Sheet ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37216354/