我正在尝试将Google Map API v2添加到我的应用中并遇到一些困难。我希望地图不会占据整个屏幕,而只是我确定的一定大小。除了这张地图之外,视图上还有其他东西。
目前我有以下代码,它只是一直向我显示一张空白地图。我相信这是因为我想我正在混合v1和v2属性。我不认为这是一个关键问题。
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<ImageButton
android:id="@+id/splash_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo_need2buythis"
android:layout_marginBottom="16dp"
android:layout_gravity="center_horizontal"
android:background="@android:color/transparent"/>
<LinearLayout
android:id="@+id/main_menu_local_button"
style="@style/MainMenuOptionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/add_location_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textStyle="bold" />
<com.google.android.gms.maps.MapView
android:id="@+id/add_location_map_view"
android:layout_width="fill_parent"
android:layout_height="300dp" />
</LinearLayout>
public class AddLocationFragment extends Fragment {
public static final String TAG = "com.myapp.android.myapp.AddLocationFragment";
MapView mapView;
GoogleMap map;
public static AddLocationFragment newInstance() {
Bundle args = new Bundle();
AddLocationFragment fragment = new AddLocationFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_add_location, parent, false);
TextView currentLocationText = (TextView) v.findViewById(R.id.add_location_current);
mapView = (MapView) v.findViewById(R.id.add_location_map_view);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.2137, -77.4358), 10);
map.animateCamera(cameraUpdate);
return v;
}
}