我是 android 新手,我想在 Tabhost 上实现谷歌地图。我有三个标签,在第三个标签中,我想实现谷歌地图版本 2。
除了谷歌地图选项卡外,一切都很好。它只显示标题和标题上的标记。它不显示谷歌地图。
这是我的 Tabhost.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<TabHost
android:id="@+id/tabhost"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ffffff">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="@+id/layTab"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@drawable/btm_bar"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/layTab"
android:layout_alignParentLeft="true" >
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
这是 Tabhost.java 类
public class Tabhost extends Activity {
TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabhost);
Resources res = getResources();
LocalActivityManager mlam = new LocalActivityManager(this, false);
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
mlam.dispatchCreate(savedInstanceState);
tabHost.setup(mlam );
Intent intent;
// Tab for Photos
TabSpec list = tabHost.newTabSpec("list");
list.setIndicator("", getResources().getDrawable(R.drawable.ic_launcher));
Intent listIntent = new Intent(this, MapList.class);
list.setContent(listIntent);
TabSpec account = tabHost.newTabSpec("account");
account.setIndicator("", getResources().getDrawable(R.drawable.lock));
Intent accountIntent = new Intent(this, FrontPage.class);
account.setContent(accountIntent);
TabSpec Map = tabHost.newTabSpec("Map");
nearby.setIndicator("", getResources().getDrawable(R.drawable.nearby));
Intent nearbyIntent = new Intent(this, Next.class);
nearby.setContent(nearbyIntent);
tabHost.addTab(list);
tabHost.addTab(account);
tabHost.addTab(Map);
tabHost.setCurrentTab(0);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"tab working", 1000).show();
finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
this is my Map_activity
public class Map extends FragmentActivity implements OnMyLocationChangeListener {
GoogleMap Gmap;
Marker blueMarker,redMarker;
Location location;
LocationManager service;
String provider;
Criteria criteria;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
/*
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);*/
/* int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else {
*/
// gps = new GPSTracker(Next.this);
Gmap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map1)).getMap();
Gmap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
Gmap.getUiSettings().setCompassEnabled(true);
Gmap.getUiSettings().setZoomControlsEnabled(true);
Gmap.getUiSettings().setZoomGesturesEnabled(true);
Gmap.getUiSettings().setScrollGesturesEnabled(true);
ConnectivityManager connectivityManager = (ConnectivityManager)
Next.this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobileInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifiInfo.isConnected() || mobileInfo.isConnected()) {
service = (LocationManager) getSystemService(LOCATION_SERVICE);
criteria = new Criteria();
provider = service.getBestProvider(criteria, false);
location = service.getLastKnownLocation(provider);
latitude= location.getLatitude();
longitude=location.getLongitude();
Gmap.setMyLocationEnabled(true);
Gmap.setOnMyLocationChangeListener(this);
final LatLng myLocation = new LatLng(latitude, longitude);
blueMarker= Gmap.addMarker(new MarkerOptions()
.position(myLocation)
.title("my Position")
.snippet("This is you")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.mark_blue)));
Gmap.moveCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 10));
}
}
这是我的 Map_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
任何人解决这个问题