【问题标题】:FAB is hiding under Bottom SheetFAB 隐藏在底部表下
【发布时间】:2016-06-01 15:47:54
【问题描述】:

我有以下 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,而不是它.

其实它显示为,

出了什么问题?有什么想法吗?

【问题讨论】:

    标签: android floating-action-button bottom-sheet


    【解决方案1】:
    <LinearLayout
            android:id="@+id/layoutBottomSheet"
            android:elevation="@dimen/global_margin"
            ...>
    

    layoutBottomSheet 可能有太多的高度,FloatingActionButton 的默认高度是4dp,这就是你的按钮隐藏在较高布局后面的原因。

    尝试低于或等于4dp的海拔值

    【讨论】:

      【解决方案2】:

      您可以在 FAB 上调用 setCompatElevation(...),其值高于底部图纸高度(如果您使用 style="@style/Widget.Design.BottomSheet.Modal",则为 16dp)以确保它位于顶部。

      【讨论】:

        【解决方案3】:

        我在 FloatingActionBButton 中添加了 app:layout_dodgeInsetEdges="bottom" 并在 View 中添加了 app:layout_insetEdge="bottom" 的底部表单行为:

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end|bottom"
                android:layout_margin="16dp"
                android:clickable="true"
                android:focusable="true"
                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"
                />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-03-12
          • 2019-01-13
          • 2017-06-11
          • 2021-02-14
          • 2012-08-16
          • 1970-01-01
          • 1970-01-01
          • 2016-04-06
          相关资源
          最近更新 更多