2
나는 안드로이드를 처음 접했고 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
있습니다 0<?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이
당신의 activity_android_tab_layout.xml TabWidget에<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>
관련 코드를 게시 할 수 있습니까? 그렇지? 너는 거의 모든 것을 붙여 넣었다. – Raptor
코드 편집을 시도했습니다. 난 그냥 activity_android_tab_layout.xml을 편집 할 수 없었다. 어떤 것들이 중요한지 잘 모르겠다. – bers