я пытался получить нижний лист ниже на карте, и я получаю ошибку, которую я не знаю, откуда она - PullRequest
0 голосов
/ 22 января 2020

Это мой код. Добро пожаловать. java

    package com.example.yanitow;


    import com.example.yanitow.Tools;

    import androidx.annotation.NonNull;
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.appcompat.widget.Toolbar;
    import androidx.constraintlayout.widget.ConstraintLayout;
    import androidx.coordinatorlayout.widget.CoordinatorLayout;
    import androidx.fragment.app.FragmentActivity;


    import android.app.Dialog;
    import android.location.Location;
    import android.location.LocationListener;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    import android.widget.Toast;


    import com.google.android.gms.maps.CameraUpdate;
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;
    import com.google.android.material.bottomsheet.BottomSheetBehavior;
    import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
    import com.google.android.material.floatingactionbutton.FloatingActionButton;

    import butterknife.ButterKnife;
    import butterknife.OnClick;

    public class Welcome extends AppCompatActivity {
        private GoogleMap mMap;
        private BottomSheetBehavior bottomSheetBehavior;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_welcome);

            initMapFragment();
            initComponent();
            Toast.makeText(this, "Swipe up bottom sheet", Toast.LENGTH_SHORT).show();
        }


        private void initComponent() {
            // get the bottom sheet view
            LinearLayout llBottomSheet = (LinearLayout) findViewById(R.id.bottom_sheet);

            // init the bottom sheet behavior
            bottomSheetBehavior = BottomSheetBehavior.from(llBottomSheet);

            // change the state of the bottom sheet
            bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

            // set callback for changes
            bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
                @Override
                public void onStateChanged(@NonNull View bottomSheet, int newState) {

                }

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

                }
            });

            ((FloatingActionButton) findViewById(R.id.fab_directions)).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    try {
                        mMap.animateCamera(zoomingLocation());
                    } catch (Exception e) {
                    }
                }
            });
        }

        private void initMapFragment() {
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            mapFragment.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(GoogleMap googleMap) {
                    mMap = Tools.configActivityMaps(googleMap);
                    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(37.7610237, -122.4217785));
                    mMap.addMarker(markerOptions);
                    mMap.moveCamera(zoomingLocation());
                    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                        @Override
                        public boolean onMarkerClick(Marker marker) {
                            bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                            try {
                                mMap.animateCamera(zoomingLocation());
                            } catch (Exception e) {
                            }
                            return true;
                        }
                    });
                }
            });
        }

        private CameraUpdate zoomingLocation() {
            return CameraUpdateFactory.newLatLngZoom(new LatLng(37.76496792, -122.42206407), 13);
        }

    }

это приветствуемое действие

activity_welcome. xml

<?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:layout_width="match_parent"
        android:layout_height="match_parent">

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- search bar layout -->
        <include
            android:id="@+id/search_bar"
            layout="@layout/include_card_view_search_bar" />


        <!--bottom sheet container-->
        <include layout="@layout/sheet_map" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_directions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/spacing_smlarge"
            android:clickable="true"
            android:tint="@android:color/white"
            app:fabSize="normal"
            app:layout_anchor="@id/bottom_sheet"
            app:layout_anchorGravity="top|end"
            app:rippleColor="@android:color/white"
            android:src="@drawable/ic_pin_drop_black_24dp" />


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

this is the sheet_map

    sheet_map.xml
    ```<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:orientation="vertical"
        app:behavior_hideable="true"
        app:behavior_peekHeight="85dp"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            app:cardCornerRadius="1dp"
            app:cardElevation="20dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <View
                    android:layout_width="30dp"
                    android:layout_height="5dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/ic_keyboard_arrow_up_black_24dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/spacing_xxlarge"
                    android:layout_marginStart="@dimen/spacing_xxlarge"
                    android:gravity="center_vertical"
                    android:minHeight="50dp"
                    android:paddingEnd="@dimen/spacing_large"
                    android:paddingLeft="@dimen/spacing_large"
                    android:paddingRight="@dimen/spacing_large"
                    android:paddingStart="@dimen/spacing_large"
                    android:text="Dandelion Chocolate"
                    android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="@dimen/spacing_large">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/spacing_middle"
                        android:layout_marginLeft="@dimen/spacing_xxlarge"
                        android:layout_marginStart="@dimen/spacing_xxlarge"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <androidx.appcompat.widget.AppCompatRatingBar
                            style="@style/Yellow.Small.AppCompatRatingBar"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:numStars="5"
                            android:rating="3.5"
                            android:stepSize="0.5"
                            android:theme="@style/Yellow.Small.AppCompatRatingBar" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="4.7 (51)"
                            android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

                    </LinearLayout>

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_marginLeft="@dimen/spacing_xxlarge"
                        android:layout_marginStart="@dimen/spacing_xxlarge"
                        android:background="@color/grey_10" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:layout_marginLeft="@dimen/spacing_xxlarge"
                        android:layout_marginStart="@dimen/spacing_xxlarge"
                        android:gravity="center_vertical"
                        android:text="12 min away"
                        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                        android:textColor="@color/colorPrimary" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_marginLeft="@dimen/spacing_xxlarge"
                        android:layout_marginStart="@dimen/spacing_xxlarge"
                        android:background="@color/grey_10" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/spacing_middle"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical"
                            android:orientation="horizontal">

                            <ImageButton
                                android:layout_width="wrap_content"
                                android:layout_height="?attr/actionBarSize"
                                android:background="@android:color/transparent"
                                android:tint="@color/grey_20"
                                android:src="@drawable/ic_location_on_black_24dp" />

                            <View
                                android:layout_width="@dimen/spacing_mxlarge"
                                android:layout_height="0dp" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:text="740 Valencia St, San Francisco, CA"
                                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                                android:textColor="@color/grey_90" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical"
                            android:orientation="horizontal">

                            <ImageButton
                                android:layout_width="wrap_content"
                                android:layout_height="?attr/actionBarSize"
                                android:background="@android:color/transparent"
                                android:tint="@color/grey_20"
                                android:src="@drawable/ic_schedule_black_24dp" />

                            <View
                                android:layout_width="@dimen/spacing_mxlarge"
                                android:layout_height="0dp" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:text="(415) 349-0942"
                                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                                android:textColor="@color/grey_90" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical"
                            android:orientation="horizontal">

                            <ImageButton
                                android:layout_width="wrap_content"
                                android:layout_height="?attr/actionBarSize"
                                android:background="@android:color/transparent"
                                android:tint="@color/grey_20"
                                android:src="@drawable/ic_schedule_black_24dp" />

                            <View
                                android:layout_width="@dimen/spacing_mxlarge"
                                android:layout_height="0dp" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:text="Wed, 10 AM - 9 PM"
                                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                                android:textColor="@color/grey_90" />

                        </LinearLayout>

                    </LinearLayout>

                </LinearLayout>

            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </LinearLayout>

ошибка, которую я сохраняю получение android .view.InflateException: двоичная XML строка файла # 2: ошибка надувания класса android .support.design.widget.CoordinatorLayout

Я перепробовал все, что мог, и посмотрел несколько раз, но ничего не работает

1 Ответ

0 голосов
/ 22 января 2020

Изменение тегов макета для использования androidx

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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">


</androidx.coordinatorlayout.widget.CoordinatorLayout>``
...