我有以下 XML:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/app_bar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<fragment
android:id="@+id/fragment1"
android:name="com.xyz.Fragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:layout="@layout/fragment_layout1" />
</LinearLayout>
<LinearLayout
android:id="@+id/layoutBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/global_margin"
android:orientation="vertical"
app:layout_behavior="@string/bottom_sheet_behavior">
<fragment
android:id="@+id/fragment2"
android:name="com.xyz.Fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
tools:layout="@layout/fragment_layout2" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/global_margin"
android:layout_marginRight="@dimen/global_margin"
android:src="@drawable/ic_add_white_24dp"
app:borderWidth="0dp"
app:elevation="4dp"
app:layout_anchor="@id/layoutBottomSheet"
app:layout_anchorGravity="top|right|end" />
</android.support.design.widget.CoordinatorLayout>
布局应显示为 Fragment1
,然后在 Fragment2
下方,FAB 锚定到 Fragment2
但是,上方 Fragment2
而不是在 下。
实际上它显示为,
出了什么问题?有什么想法吗?
最佳答案
<LinearLayout
android:id="@+id/layoutBottomSheet"
android:elevation="@dimen/global_margin"
...>
layoutBottomSheet
可能有太多高度,FloatingActionButton 的默认高度是 4dp
,这就是你的按钮隐藏在较高布局后面的原因。
尝试使用低于或等于 4dp
关于android - FAB 隐藏在 Bottom Sheet 下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37573348/