我试图将MapView添加到扩展FrameLayout的自定义视图中。这是我的自定义视图:
public class LocationStepLayout extends FrameLayout implements StepLayout,OnMapReadyCallback{
private MapView mMapView;
private void initStepLayout(LocationStep step) {
...
LayoutInflater inflater = LayoutInflater.from(getContext());
inflater.inflate(R.layout.location_layout,this,true);
mMapView = findViewById(R.id.myMap);
mMapView.getMapAsync(this);
...
}
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng sydney = new LatLng(-33.852, 151.211);
googleMap.addMarker(new MarkerOptions().position(sydney)
.title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
这是我的布局:
<com.google.android.gms.maps.MapView
android:id="@+id/myMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:context="com.example.mapwithmarker.MapsMarkerActivity">
</com.google.android.gms.maps.MapView>
但地图不会在视图中显示。我做错了什么?
提前致谢:)