如何在活动中使用mapView?

时间:2013-06-15 11:32:26

标签: android android-mapview android-maps android-maps-v2

在我的应用程序中,使用包含其他布局主XML 中包含两个视图,因为第一个视图只有简单的文本视图,而在第二个视图中我有地图视图在我的主XML文件中,当我单击第一个按钮以显示带有文本视图的第一个视图时,我有两个按钮,当我单击第二个按钮时,我想要隐藏第一个视图并显示带有地图视图的第二个视图。我不知道如何在主要活动中显示地图视图。任何人都知道请帮我解决这个问题。

3 个答案:

答案 0 :(得分:0)

首先说出你使用的谷歌地图版本 v1 - https://developers.google.com/maps/documentation/android/v1/ v2 - https://developers.google.com/maps/documentation/android/start

通常您需要做的是在FrameLayout中放置两个布局,并在单击特定按钮时显示/隐藏其中一个布局。但更具体地说,我们需要查看您的代码。

答案 1 :(得分:0)

1)GoogleMapsV1使用MapView。但它需要谷歌在注册时为个人开发者提供的api密钥。

不幸的是,谷歌关闭了它,你必须使用带有新V2键的GoogleMapV2。

此外,使用片段进行锻炼,因为我们正在使用Fragment或SupportFragment。

2)你可以使用一个FrameLayout,其中你的两个重叠视图有id。这样您就可以根据需要在同一位置显示或隐藏视图。

答案 2 :(得分:0)

请尝试使用以下代码。

<LinearLayout
    android:id="@+id/buttonLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2" />
</LinearLayout>

<ViewFlipper
    android:id="@+id/viewFliper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/buttonLayout" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:apiKey="your map key map_key"
        android:clickable="true"
        android:enabled="true"
        android:focusable="true"
        android:focusableInTouchMode="true" />
</ViewFlipper>