【问题标题】:Android persistent bottom sheet initial visibilityAndroid 持久化底页初始可见性
【发布时间】:2017-07-27 09:33:36
【问题描述】:

我正在尝试在我的布局中实现一个持久的底部工作表 - 不能完全隐藏,但总是从底部窥视并且可以扩展到全高。这是我的布局:

<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() 中调用bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED) 来显示它。奇怪的是,这只会稍微扩展它 - 超过指定的窥视高度,但低于它应该占据的全部高度。在它以这种状态出现后,我可以将它上下拖动到它应该在的位置并且它工作正常。问题是屏幕上的初始着陆被搞砸了。

我确信有一种方法可以使这个工作正常工作,因此底部工作表最初出现在它的窥视高度。有什么想法吗?

【问题讨论】:

    标签: android android-layout android-design-library bottom-sheet


    【解决方案1】:

    正如经常发生的那样 - 您在提出问题后会找到答案。我的问题是底部工作表视图上的android:layout_gravity="center|bottom" 设置。删除修复它。

    【讨论】:

      猜你喜欢
      • 2016-03-09
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多