Как свернуть вид в нижней части экрана в Android с помощью координатора макета? - PullRequest
0 голосов
/ 26 июня 2018

Может ли кто-нибудь помочь мне сделать так, чтобы складная панель инструментов шла вниз, не выходя из экрана?

Исходный вид:

enter image description here

После прокрутки вниз:

enter image description here

Это то, что я пробовал, но панель инструментов всегда прокручивается вверх и исчезает:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/search_place_root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.location.SearchPlaceActivity">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/search_place_header"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/home_background"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <EditText
            android:id="@+id/search_place_et"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="25dp"
            android:layout_marginStart="57dp"
            android:layout_marginTop="8dp"
            android:background="#e3e3e3"
            android:padding="10dp"
            android:textColor="@color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/search_place_back_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="25dp"
            app:layout_constraintBottom_toBottomOf="@+id/search_place_et"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/search_place_et"
            app:srcCompat="@drawable/back" />
    </android.support.constraint.ConstraintLayout>


    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/search_place_header"
        android:foregroundGravity="bottom">


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


            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.constraint.ConstraintLayout
                    android:id="@+id/search_place_results_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/list_search"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:background="@color/white"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />


                    <android.support.constraint.ConstraintLayout
                        android:layout_width="0dp"
                        android:layout_height="122dp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/list_search">

                        <ImageView
                            android:id="@+id/imageView22"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="25dp"
                            android:src="@drawable/location_pin"
                            app:layout_constraintBottom_toBottomOf="@id/search_place_use_my_current_loc_tv"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="@id/search_place_use_my_current_loc_tv" />

                        <TextView
                            android:id="@+id/search_place_use_my_current_loc_tv"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="22dp"
                            android:layout_marginTop="34dp"
                            android:fontFamily="@font/opensanssemibold"
                            android:letterSpacing="0.02"
                            android:lineSpacingExtra="12sp"
                            android:text="@string/use_my_current_location"
                            android:textColor="#000000"
                            android:textSize="15sp"
                            app:layout_constraintStart_toEndOf="@+id/imageView22"
                            app:layout_constraintTop_toTopOf="parent" />
                    </android.support.constraint.ConstraintLayout>
                </android.support.constraint.ConstraintLayout>
            </android.support.design.widget.CollapsingToolbarLayout>

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


</android.support.constraint.ConstraintLayout>

Как я могу сделать так, чтобы весь мой контент опустился на дно и немного сжался?

1 Ответ

0 голосов
/ 26 июня 2018

Xml

  <LinearLayout 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:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="info.androidhive.bottomsheet.MainActivity"
    tools:showIn="@layout/activity_main">

    <-Your Views->

 </LinearLayout>

Java

BottomSheetBehavior sheetBehavior = BottomSheetBehavior.from(layoutBottomSheet);

/**
         * bottom sheet state change listener
         * we are changing button text when sheet changed state
         * */
        sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                switch (newState) {
                    case BottomSheetBehavior.STATE_HIDDEN:
                        break;
                    case BottomSheetBehavior.STATE_EXPANDED: {
                        btnBottomSheet.setText("Close Sheet");
                    }
                    break;
                    case BottomSheetBehavior.STATE_COLLAPSED: {
                        btnBottomSheet.setText("Expand Sheet");
                    }
                    break;
                    case BottomSheetBehavior.STATE_DRAGGING:
                        break;
                    case BottomSheetBehavior.STATE_SETTLING:
                        break;
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });

Подробнее

...