协调器布局中的地图片段重叠底部工作表

时间:2017-05-21 13:11:20

标签: android android-layout android-coordinatorlayout

我正在尝试使用协调器布局在地图上显示底部工作表。工作表显示片刻,然后在创建地图时消失。然后纸张消失。 该表格应该在标记点击时展开。 logcat显示单击标记时表单已展开。

以下是我在MapActivity中的功能

 void setupMap() {

    View fml= findViewById(R.id.bottomSheet);

        final BottomSheetBehavior behavior = BottomSheetBehavior.from(fml);
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                switch (newState) {
                    case BottomSheetBehavior.STATE_DRAGGING:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_DRAGGING");
                        break;
                    case BottomSheetBehavior.STATE_SETTLING:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_SETTLING");
                        break;
                    case BottomSheetBehavior.STATE_EXPANDED:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_EXPANDED");
                        break;
                    case BottomSheetBehavior.STATE_COLLAPSED:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_COLLAPSED");
                        break;
                    case BottomSheetBehavior.STATE_HIDDEN:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_HIDDEN");
                        break;



            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                Log.i("BottomSheetCallback", "slideOffset: " + slideOffset);
            }
        });




        mMap.setPadding(2, 250, 2, 2);
        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                Log.d("markerclick", "onMarkerClick: ");

                _marker = marker;



                if (behavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
                    behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                }else {
                    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
                fml.bringToFront();


                return true;
            }
        });

        mMap.setOnCameraIdleListener(this);
        mMap.setOnMapClickListener(this);
        mMap.setOnCameraMoveListener(this);




    }
}

这是Map Activity的xml文件

<android.support.design.widget.CoordinatorLayout
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:layout_height="match_parent"
android:layout_width="match_parent"

>
<RelativeLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"
        />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/gps"
        />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="top"
        android:background="#ffffff"
        android:outlineProvider="none"
        android:baselineAligned="true"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="4dp"
        android:paddingBottom="4dp">
        <AutoCompleteTextView
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:id="@+id/autotxt_serchMap"
            android:textCursorDrawable="@null"

            android:backgroundTint="#ffffff"
            />
        <ImageButton
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:id="@+id/btn_serchMap"
            android:src="@drawable/search2"
            android:background="#ffffff" />
    </RelativeLayout>
    <!-- <FrameLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentBottom="true"
         android:translationY="@dimen/docorPopupFragmentHeight"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:id="@+id/doctorDetailFrame">
          android:translationY="@dimen/docorPopupFragmentHeight"
     </FrameLayout>!-->


</RelativeLayout>
<include
    layout="@layout/docdetail"
    android:id="@+id/bottomSheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:behavior_hideable="true"
    app:behavior_peekHeight="60dp"
    android:layout_centerHorizontal="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>

底部工作表布局如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:uber="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
        <RelativeLayout>
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scheduleLayout"

        android:gravity="center">


        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:id="@+id/DocDet_MondayChkBx"
            android:layout_alignBottom="@+id/textView8"
            android:layout_toRightOf="@+id/DocDet_MondayTo"
            android:layout_marginLeft="20dp"
            android:enabled="false" />


        </RelativeLayout>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:textSize="18dp"/>

</RelativeLayout>
</FrameLayout>

您的指导将不胜感激

0 个答案:

没有答案