如何将底部表格延伸到工具栏的底部,而不是在工具栏下面?

时间:2018-04-17 19:59:52

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

我有bottomSheetLayout,当它进入扩展模式进入toolbarLayout时,我想到达工具栏?我将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>

1 个答案:

答案 0 :(得分:0)

不要在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>

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

希望这会对您有所帮助。