0

나는 Android에 처음입니다. Tabhost.I에 Google지도를 구현하고 싶습니다. 세 번째 탭에 있습니다. 구현하고 싶습니다. Google지도 버전 2.Google지도 탭볼 with 안드로이드 api v2는 tabhost의 fragmentActivity에서만 제목 문제를 표시하는 Google지도를 표시하지 않습니다.

모두 잘되고 있습니다. Google지도 탭을 제외하고는 모두 괜찮습니다. 제목과 마커 만 표시됩니다. Google지도는 표시되지 않습니다.

이이 문제를 해결 어느 하나 내 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> 

내 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)); 
} 
} 

입니다

+0

이이 문제를 해결할 수 있었나요 ??? – Zeba

답변

0

나는 그는 동일한 문제 (Google지도 v2는 탭에 회색 격자 만 표시했으나 작동하지 않는 탭이없는 주요 활동으로로드하는 경우). 그럼 mMapFragment.onResume()을 추가했는데 이제는 탭에서 작동합니다! 여기

mMapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)); 
mMapFragment.onResume(); // needed to get the map to display immediately 

내가 찾은 솔루션 :이 시도 https://stackoverflow.com/a/16960527/185493