タブでグーグルマップを使用し、他の何かで使用するシンプルなアプリを作成しています。問題は、向きを変えると地図が再作成されるので、latlng0,0に移動することです。
これが私のコードです
MainAcitivy.java
private static final String MAP_FRAGMENT_TAG = "map";
private static final String DUMMY_FRAGMENT_TAG = "DUMMY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the action bar to show tabs.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
//
// // For each of the sections in the app, add a tab to the action bar.
actionBar.addTab(actionBar
.newTab()
.setText(R.string.title_section1)
.setTabListener(
new TabListener<SupportMapFragment>(this,
MAP_FRAGMENT_TAG, SupportMapFragment.class)));
actionBar
.addTab(actionBar
.newTab()
.setText(R.string.title_section2)
.setTabListener(
new TabListener<DummySectionFragment>(this,
DUMMY_FRAGMENT_TAG,
DummySectionFragment.class)));
}
TabListener.java
public class TabListener<T extends Fragment> implements ActionBar.TabListener {
private Fragment mFragment;
private final SherlockFragmentActivity mActivity;
private final String mTag;
private final Class<T> mClass;
public TabListener(SherlockFragmentActivity activity, String tag,
Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
}
/* The following are each of the ActionBar.TabListener callbacks */
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = mActivity.getSupportFragmentManager()
.findFragmentByTag(mTag);
}
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
}