我尝试在标签式活动中对Google地图活动进行充气。我的应用程序没有编译时或运行时错误。问题是,我看不到标记,只是布局膨胀。 这是我的MainActivity的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_page, container, false);
RelativeLayout mainview = (RelativeLayout) rootView.findViewById(R.id.main_view);
int num;
RelativeLayout myLayout = (RelativeLayout) rootView.findViewById(R.id.main_view);
num= getArguments().getInt(ARG_SECTION_NUMBER);
if (num==1){
View child = getLayoutInflater(savedInstanceState).inflate(R.layout.maps_activity, null);
myLayout.addView(child);
} else if (num==2){
} else if (num==3){
} else{
}
return rootView;
}
这是我的maps_activity.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.codestarsnepal.aashish.know_your_air.KnowYourAir" />
这是我的MapsActivity.java
public class KnowYourAir extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_know_your_air);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));