安卓持久化底部菜单初始可见性

8

我正在尝试在布局中实现一个持久的底部面板 - 无法完全隐藏,但始终从底部窥视并可以扩展到完整高度。这是我的布局:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">

        <!-- main content -->

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutBottomSheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        android:background="@drawable/custom_background"
        android:clipToPadding="false"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        app:behavior_hideable="false"
        app:behavior_peekHeight="50dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <!-- bottom sheet content -->

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

我希望底部的表单在我进入屏幕时就可见且折叠,但实际上它是隐藏的。我可以通过在onCreate()中调用bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED)来显示它。奇怪的是,这只会使它稍微展开一点,比指定的最小高度要高,但比它应该占据的完整高度要低。在它以这种状态出现后,我可以将其拖动到正确位置,然后它就能正常工作。问题在于初始着陆屏幕时出了问题。
我相信有一种方法可以让底部表单最初以它的最小高度出现。有什么想法吗?
1个回答

4
通常情况下,你提出问题后才能找到答案。我的问题在于底部表视图上设置的android:layout_gravity="center|bottom"。移除该设置后问题得到解决。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接