java - 我一直在尝试在 map 下面获取底部表格,但收到错误,我不知道它来自哪里

标签 java android android-studio android-layout android-fragments

这是我的代码 欢迎.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

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 时出错

我已经尝试了一切,并查了好几次,但似乎没有任何效果

最佳答案

更改布局标签以使用 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>``

关于java - 我一直在尝试在 map 下面获取底部表格,但收到错误,我不知道它来自哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59863076/

相关文章:

音频缓冲区上的 java.lang.OutOfMemoryError

java - 如何修复迭代期间添加项目时的 ConcurrentModificationException 错误

java - 在java中写入日志文件是通过文件名还是其他东西(如 inode 、文件句柄等)来跟踪的?

c# - Xamarin 安卓 : Cannot choose compile version

java - 如何从代码中安全地删除 Java 中的对象?

android - 如何在 viewpager 和分段 Controller 中实现不同 ListView 的搜索功能

android - 如何使用 Android Studio 在模块中添加 flavor ?

android - 找不到Android开发者官网提到的示例工程

java - 从 javabean 创建不可变对象(immutable对象)

java - 推荐的框架、库和概念