如何将FAB锚定在折叠的底部工作表中的屏幕底部?

时间:2019-11-15 17:04:58

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

因此,我已经基于BottomSheetBehavior和标签创建了一个布局:

main_fragment.xml

   <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/mainLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.mapbox.mapboxsdk.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            mapbox:mapbox_cameraZoom="11">

        </com.mapbox.mapboxsdk.maps.MapView>

        <androidx.viewpager.widget.ViewPager
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
            app:behavior_hideable="false"
            app:behavior_peekHeight="200dp"
            android:background="#fff"
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <com.google.android.material.tabs.TabItem android:text="@string/tab1" />
                <com.google.android.material.tabs.TabItem android:text="@string/tab2" />
                <com.google.android.material.tabs.TabItem android:text="@string/tab3" />
            </com.google.android.material.tabs.TabLayout>
        </androidx.viewpager.widget.ViewPager>

tab1_fragment.xml

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
            android:id="@+id/addButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:onClick="@{() -> viewModel.add()}"
            android:text="@string/new"
            app:icon="@drawable/ic_add_black_24dp"
            android:layout_gravity="center|bottom"
            android:layout_margin="@dimen/margin_medium"
            />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

它可以正常工作,但是,仅当我将底页向上拉时,我才能访问FAB:

Bottom Sheet Collapsed

Bottom Sheet Expanded to Full Screen

即使底部表没有任何严重的变形也可以折叠,是否有办法在屏幕底部显示FAB?

0 个答案:

没有答案
相关问题