2013-10-30 46 views
2

我是新来的android和没有Java的经验。 我正在制作具有选项卡的应用程序。其中一个标签,点击时必须显示googlemap。我成功地做到了这一点,问题是地图显示时,它不显示选项卡,所以我不能返回到其他选项卡。其他选项卡的目的是显示在地图视图上选择的位置。任何人都可以帮助我吗?下面是我的代码如何显示标签内的地图

MainActivity.java

package jp.co.gpsloader; 

    import android.app.Activity; 
    import android.app.ActivityGroup; 
    import android.content.Context; 
    import android.content.Intent; 
    import android.database.Cursor; 
    import android.database.sqlite.SQLiteDatabase; 
    import android.os.Bundle; 
    import android.widget.TabHost; 
    import android.widget.TabHost.TabSpec; 
    //Used Activity group because tabhost was used ActivityGroup 
    @SuppressWarnings("deprecation") 
    public class MainActivity extends ActivityGroup { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     // Then do Main Activity name 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_android_tab_layout); 
     TabHost tabHost = (TabHost) findViewById(R.id.tabHost); 
     tabHost.setup(); 

     // Then added an Intent on our new tab 
     TabSpec spec2 = tabHost.newTabSpec("Location"); 
     spec2.setIndicator("Location"); 
     spec2.setContent(new Intent(this, SampleMapClickListener.class)); 

     TabSpec spec3 = tabHost.newTabSpec("The GPS"); 
     spec3.setIndicator("The GPS"); 
     spec3.setContent(new Intent(this, GpsMain.class)); 


     Context ctx = this.getApplicationContext(); 
     Intent i = new Intent(ctx, GpsMain.class); 
     spec3.setContent(i); 

     // Add your new tab in the tabhost here 
     tabHost.addTab(spec2); 
     tabHost.addTab(spec3); 

     // This is needed for Activity group 
     tabHost.setup(this.getLocalActivityManager()); 

     tabHost.setCurrentTab(0); 
    } 
} 

GPSMain.java

package jp.co.gpsloader; 

import android.os.*; 
import android.widget.Toast; 
import android.app.*; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor;  
import com.google.android.gms.internal.v; 
import com.google.android.gms.maps.*; 
import com.google.android.gms.maps.GoogleMap.*; 
import com.google.android.gms.maps.model.*; 

public class GpsMain extends Activity { 
MapFragment mf; 
GoogleMap gm; 
MarkerOptions marker; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mf = MapFragment.newInstance(); 
    FragmentManager fm = getFragmentManager(); 
    FragmentTransaction ft = fm.beginTransaction(); 
    ft.add(android.R.id.content, mf); 
    ft.commit(); 
} 
public void onResume() { 
    super.onResume(); 

    // created map 
    gm = mf.getMap(); 
    gm.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
    gm.setMyLocationEnabled(true); 

    // set latitude and longitude 
    LatLng ltn = new LatLng(40, 135); 

    // create marker 
    marker = new MarkerOptions(); 
    marker.position(ltn); 

    // operation can be done, when click happens 
    gm.setOnMapClickListener(new SampleMapClickListener()); 
} 

class SampleMapClickListener implements OnMapClickListener { 

    @Override 
    public void onMapClick(LatLng ltn) { 
     marker = new MarkerOptions(); 
     marker.position(ltn); 
     gm = mf.getMap(); 
     // add marker 
     gm.addMarker(marker); 

    } 

} 

}

activity_android_tab_layout.xml

<?xml version="1.0" encoding="utf-8"?> 

<TabHost android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/tabHost" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<TabWidget 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@android:id/tabs" 
/> 
<FrameLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@android:id/tabcontent" 
> 
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/tab1" 
android:orientation="vertical" 
android:paddingTop="60px" 
> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="100px" 
android:text="This is tab1" 
android:id="@+id/txt1" 
/>  

</LinearLayout> 

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/tab2" 
android:orientation="vertical" 
android:paddingTop="60px" 
> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="100px" 
android:text="This is tab 2" 
android:id="@+id/txt2" 
/> 

</LinearLayout> 


</FrameLayout> 

</TabHost> 

map.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<com.google.android.gms.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="100dip" 
    android:layout_height="100dip" 
    android:layout_alignParentTop="true" 
    android:layout_alignRight="@+id/textView1" 
    android:layout_marginRight="15dp" > 
</com.google.android.gms.maps.MapView> 


</RelativeLayout> 
+1

你能否在相关代码上发表你呢?你粘贴了几乎所有东西。 – Raptor

+0

我试着编辑代码。我只是不能编辑activity_android_tab_layout.xml。即时通讯不太确定哪些是重要的。 – bers

回答

0

在您activity_android_tab_layout.xml TabWidget,指定的高度,可以说50dp:

 android:layout_height="50dp" 

在您map.xml,分配marginBottom,也是50dp:

android:layout_marginBottom="50dp" 
相关问题