【问题标题】:How to add Map to Android Master/Detail Flow properly?如何正确地将地图添加到 Android 主/详细信息流?
【发布时间】:2017-08-31 20:18:35
【问题描述】:

在 Android SDK 中,我使用 Master/Detail Flow 模板创建了一个应用程序,现在我想将 Palette 中的 Google MapView 添加到 activity_item_detail.xml,如下所示:

attempt to insert Map into Master/Detail Flow

项目编译,但是当我在模拟器中启动应用程序并选择项目列表中的项目时,模拟器中的应用程序崩溃。我不确定如何解决这个问题。我必须执行哪些步骤?我必须在哪里添加其他代码?顺便说一句,如果我只是向 item_detail_container 添加一个按钮,也会发生同样的事情。非常感谢您的帮助!

activity_item_detail.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_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.ralfmatz.testapplication.ItemDetailActivity"
    tools:ignore="MergeRootFrame">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        </android.support.design.widget.CollapsingToolbarLayout>

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/item_detail_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@+id/item_detail_container"
        app:layout_anchorGravity="top|end"
        app:srcCompat="@android:drawable/stat_notify_chat" />

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

【问题讨论】:

  • 请同时显示一些代码
  • 在项目上创建时,我没有添加其他代码,只是将地图(或按钮)从调色板拖放到 activity_item_detail.xml 窗格。

标签: android dictionary


【解决方案1】:

由于您没有显示任何 logcat 输出,我假设 您必须添加 Google Map API 才能查看地图并避免崩溃

查看地图 api 参考:https://developers.google.com/maps/documentation/android-api/config

【讨论】:

  • 感谢您的提示!我已经修改了项目,现在我可以工作了。但是地图是在不同的活动上。我会及时通知你。
猜你喜欢
  • 2017-08-29
  • 1970-01-01
  • 2011-04-02
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-13
相关资源
最近更新 更多