【问题标题】:How to extend bottomsheet till the bottom of toolbar, and not under the toolbar?如何将底页扩展到工具栏底部,而不是在工具栏下方?
【发布时间】:2018-09-27 21:59:59
【问题描述】:

我有bottomSheetLayout,当它进入扩展模式时进入工具栏布局,而我想到达工具栏?我将 layout_height 设置为 match_parent 是否需要在类中计算高度并将其设置为 deviceHeight-toolbarheight 并设置为 bottomSheet 布局高度? 我在与小吃店一起使用时遇到问题

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:animateLayoutChanges="true">

    <include
        android:id="@+id/toolbarLayout"
        layout="@layout/toolbar_with_back"
        app:toolbarViewModel="@{toolbarViewModel}" />

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchor="@+id/toolbarLayout"
        app:layout_anchorGravity="bottom"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/store_bottom_sheet"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:layout_height="match_parent"
        app:behavior_hideable="false"
        app:behavior_peekHeight="@dimen/bottom_peek_height"
        app:layout_behavior="@string/bottom_sheet_behavior">


        <android.support.constraint.ConstraintLayout
            android:id="@+id/constraintLayout"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_margin="16dp"
            android:fitsSystemWindows="true"
            android:background="@drawable/rounded_shape"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_search_black_24dp" />

            <EditText
                android:id="@+id/search_store"
                android:layout_width="0dp"
                android:layout_height="44dp"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:background="@null"
                android:hint="@string/store_hint_search"
                android:imeOptions="actionSearch"
                android:inputType="text"
                android:maxLines="1"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toRightOf="@+id/imageView"
                app:layout_constraintRight_toLeftOf="@+id/switch_filter"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.6" />

            <android.support.v7.widget.SwitchCompat
                android:id="@+id/switch_filter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </android.support.constraint.ConstraintLayout>

        <com.google.android.flexbox.FlexboxLayout
            android:id="@+id/list_filter"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:visibility="gone"
            app:dividerDrawable="@drawable/divider"
            app:flexWrap="wrap"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/constraintLayout"
            app:showDivider="beginning|middle" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:nestedScrollingEnabled="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/list_filter"
            app:layout_constraintVertical_bias="0.0" />

    </android.support.constraint.ConstraintLayout>

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

【问题讨论】:

    标签: android android-xml android-coordinatorlayout bottom-sheet


    【解决方案1】:

    不要在 CoordinatorLayout 中添加工具栏。在 CoordinatorLayout 之外添加工具栏。制作基本的线性或真实布局。

    例如:我使用 DrawerLayout 作为基本布局,如果您不希望可以删除它并简单地使用线性或真实布局。

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <include layout="@layout/toolbar" />
    
        <include layout="@layout/dashboard" />
    </LinearLayout>
    
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main2"
        app:menu="@menu/activity_main2_drawer" />
    
    </android.support.v4.widget.DrawerLayout>
    

    然后使用 CoordinatorLayout

    <?xml version="1.0" encoding="utf-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:id="@+id/dashboard"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
       //here you can add your views
    
    </LinearLayout>
    
    <!-- Adding bottom sheet after main content -->
    <include layout="@layout/bottom_sheet" />
    
    
    </android.support.design.widget.CoordinatorLayout>
    

    现在底页将完全展开,直到工具栏不在工具栏下方或工具栏上方。

    希望这会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 2015-11-23
      • 2018-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 2022-11-10
      相关资源
      最近更新 更多