0

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

4

3 回答 3

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>

于 2013-06-15T12:19:26.070 回答
0

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

不幸的是,它已被谷歌关闭,您必须使用带有新 V2 密钥的 GoogleMapV2。

另外,使用 Fragment 进行锻炼,因为这里我们使用 Fragment 或 SupportFragment。

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

于 2013-06-15T11:58:58.693 回答
0

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

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

于 2013-06-15T11:38:10.253 回答