Android应用程序使用TabHost和多个地图导致问题
我在应用程序中使用TabHost,我需要在两个不同的选项卡中显示两个地图。我已经能够集成地图,但问题是当我从一个选项卡移动到另一个选项卡时,地图会挂起/停止,并且没有响应,即地图只在其中一个屏幕上工作 下面是我的主布局的xml和类,它有TabHostAndroid应用程序使用TabHost和多个地图导致问题,android,android-tabhost,google-maps-android-api-2,Android,Android Tabhost,Google Maps Android Api 2,我在应用程序中使用TabHost,我需要在两个不同的选项卡中显示两个地图。我已经能够集成地图,但问题是当我从一个选项卡移动到另一个选项卡时,地图会挂起/停止,并且没有响应,即地图只在其中一个屏幕上工作 下面是我的主布局的xml和类,它有TabHost <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" andr
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f00"
android:foregroundGravity="top"
android:layout_above="@android:id/tabs"
/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#fff"
android:tabStripEnabled="false"
>
</TabWidget>
</RelativeLayout>
</TabHost>
package com.cotechnica.alps;
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Menu;
import android.widget.TabHost;
import com.ankitkedia.alps.R;
public class Main extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Map1.class);
spec = tabHost.newTabSpec("home").setIndicator("Map1",
getResources().getDrawable(android.R.drawable.star_on)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Map2.class);
spec = tabHost.newTabSpec("rescue").setIndicator("Map2",
getResources().getDrawable(android.R.drawable.star_big_off)
).setContent(intent);
tabHost.addTab(spec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
包com.cotechnica.alps;
导入android.os.Bundle;
导入android.app.Activity;
导入android.app.TabActivity;
导入android.content.Intent;
导入android.content.res.Resources;
导入android.view.Menu;
导入android.widget.TabHost;
阿尔卑斯山进口公司ankitkedia.R;
公共类主活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res=getResources();
TabHost TabHost=getTabHost();
TabHost.TabSpec;
意图;
//创建为选项卡启动活动的意图(要重用)
intent=newintent().setClass(这是Map1.class);
spec=tabHost.newTabSpec(“home”).setIndicator(“Map1”,
getResources().getDrawable(android.R.drawable.star_on)).setContent(intent);
tabHost.addTab(spec);
//对其他选项卡执行相同的操作
intent=newintent().setClass(这是Map2.class);
spec=tabHost.newTabSpec(“rescue”).setIndicator(“Map2”,
getResources().getDrawable(android.R.drawable.star\u big\u off)
).setContent(意图);
tabHost.addTab(spec);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
}
我看到很多人都面临着同样的问题,但没有合适的解决方案
任何帮助将不胜感激,我可以发送样品项目来源,如果需要的话
问候,,
安基特这家伙有一个很好的解决方案
请注意,这是不鼓励的,因此答案应该是搜索解决方案的终点(而不是参考文献的另一个中途停留,随着时间的推移,这些参考文献往往会过时)。请考虑在这里添加一个独立的概要,保持链接作为参考。这是答案,所以它比你们中的一些人在这里做的更好…或者根本不做任何事情!谢谢~