[英]How use the mapView in activity?
在我的應用程序中,可以使用其他布局在主XML中包含兩個視圖,其中第一個視圖僅具有簡單的文本視圖,第二個視圖中具有地圖視圖。在我的主XML文件中,當我單擊第一個按鈕以顯示時有兩個按鈕帶有文本視圖的第一個視圖,當我單擊第二個按鈕時,我想隱藏第一個視圖並以地圖視圖顯示第二個視圖。我不知道如何在主要活動中顯示地圖視圖。有誰知道請幫助我解決這個問題。
首先說出您使用的v1版本的Google地圖-https: //developers.google.com/maps/documentation/android/v1/ v2- https://developers.google.com/maps/documentation/android/start
通常,您需要做的是在FrameLayout中放置兩個布局,並在單擊特定按鈕時顯示/隱藏其中之一。 但更具體地說,我們需要查看您的代碼。
1)MapView由GoogleMapsV1使用。 但它需要由Google為注冊的個人開發者提供的api密鑰。
不幸的是,它已被google關閉,您必須將GoogleMapV2與新的V2密鑰一起使用。
另外,還需要對片段進行鍛煉,因為在這里我們使用Fragment或SupportFragment。
2)您可以使用一個FrameLayout,在其中兩個帶有id的重疊視圖。 這樣您就可以根據需要在相同位置顯示或隱藏視圖。
請嘗試使用以下代碼。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.