gpt4 book ai didi

Android MapView + Tab 示例

转载 作者:太空狗 更新时间:2023-10-29 12:58:53 26 4
gpt4 key购买 nike

我需要在选项卡上有一个 map View 。attached example展示了如果使用 Intent 如何做到这一点。现在我想更改 map View 的缩放级别。我该怎么做,尽管我正在使用 Intent (或者完全没有不同的解决方案)?

Activity 代码:

public class TabMapsExample extends TabActivity {    
TabHost mTabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context ctx = this.getApplicationContext();
//tab 1
mTabHost = getTabHost();
TabSpec tabSpec1 = mTabHost.newTabSpec("tab_test1");
tabSpec1.setIndicator("Map1");
Intent i1 = new Intent(ctx, MapTabView.class);
tabSpec1.setContent(i1);
mTabHost.addTab(tabSpec1);
//tab2
mTabHost = getTabHost();
TabSpec tabSpec2 = mTabHost.newTabSpec("tab_test1");
tabSpec2.setIndicator("Map2");
Intent i2 = new Intent(ctx, MapTabView.class);
tabSpec2.setContent(i2);
mTabHost.addTab(tabSpec2);
//tab 3
mTabHost = getTabHost();
TabSpec tabSpec3 = mTabHost.newTabSpec("tab_test1");
tabSpec3.setIndicator("Map");
Intent i3 = new Intent(ctx, MapTabView.class);
tabSpec3.setContent(i3);
mTabHost.addTab(tabSpec3);
}
}

布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/maptablayout" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:background="#000000" android:orientation="vertical">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="50px"
android:id="@+id/textview" />
<com.google.android.maps.MapView
android:id="@+id/mapview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:clickable="true"
android:apiKey="" />
</LinearLayout>
</RelativeLayout>

谢谢

最佳答案

尝试使用MapController :

    MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(10);

另见 Using Google Maps in Android

更新
您创建了多个相同布局的实例,但无法通过 ID 获取所需的 MapView 实例。您可以为每个选项卡使用单独的布局吗?还是动态创建它们?

关于Android MapView + Tab 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2027066/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com