我一直在试图插入图形页面
到动作条
设置页
,但我没能解决,即使谷歌搜索的问题。
I've been trying insert a MapView
into an ActionBar
Tab
, but I wasn't able to solve the problem even googling.
下面是主要活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.action_bar_tabs);
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().add(android.R.id.content, GigLoader.GigLoaderListFragment.newInstance()).commit();
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = getSupportActionBar().newTab().setText("Geo").setTabListener(this);
ActionBar.Tab tab2 = getSupportActionBar().newTab().setText("Lista").setTabListener(this);
getSupportActionBar().addTab(tab1);
getSupportActionBar().addTab(tab2);
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (tab.getPosition() == 0) {
fm.beginTransaction().add(android.R.id.content, GigLoader.GigLoaderListFragment.newInstance()).commit();
}
else {
fm.beginTransaction().add(android.R.id.content, GeoGigLoader.GeoGigMapFragment.newInstance()).commit();
}
}
这里的code中的 GeoGigLoader
:
public class GeoGigLoader extends FragmentMapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public static final class GeoGigMapFragment extends Fragment {
static GeoGigMapFragment newInstance() {
GeoGigMapFragment map = new GeoGigMapFragment();
return map;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.map_gigs, container, false);
MapView mapView = (MapView)view.findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
return view;
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
FragmentMapActivity
是actionbarsherlock.com库,并从这个延伸的 MapActivity
,所以它应该工作
FragmentMapActivity
is a library from actionbarsherlock.com, and this one extends from a MapActivity
, so it should work.
我得到的错误,是下一个:
The error I get, is the next one:
致命异常:主要
E / AndroidRuntime(954):android.view.InflateException:二进制XML文件中的行#2:错误充气类com.google.android.maps.MapView
E / AndroidRuntime(954):在android.view.LayoutInflater.createView(LayoutInflater.java:513)
E / AndroidRuntime(954):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
FATAL EXCEPTION: main
E/AndroidRuntime(954): android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView
E/AndroidRuntime(954): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
任何人都知道发生了什么事?
Anybody know what's happening?
解决方案是启动图形页面中的主要活动应扩展FragmentMapActivity。那么你的片段可以通过从主要活动得到它实现的MapView。
Solution is to start mapview in the main activity which should extend FragmentMapActivity. Then your fragment can implement the mapview by getting it from the main activity.
主要活动:
mMapView = new MapView(YourActivity.this, MAPS_KEY);
mMapView.setClickable(true);
Exchanger.mMapView = mMapView;
片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mMapView = Exchanger.mMapView;
return mMapView;
}
@Override
public void onDestroy() {
if(mMapView != null) {
NoSaveStateFrameLayout parentView = (NoSaveStateFrameLayout) mMapView.getParent();
parentView.removeView(mMapView);
}
super.onDestroy();
}
器是一类具有静态字段与MapView类的吧。
Exchanger is a class with a static field with mapview in it.
上一篇:在Windows 8 64位的Android工作室启动失败工作室、Windows、oid、Andr
下一篇:禁用的Android AutoCompleteTextView后,用户从下拉选择项下移用户、Andr、oid、AutoCompleteTextView