Cambiar el tamaño de un mapa en tiempo de ejecución

Quiero cambiar el tamaño de mi mapa de forma dinámica en tiempo de ejecución haciendo clic en una tecla de flecha. Mi diseño es:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MapActivity" > <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" /> 

Creo que tengo que usar MapView y setLayoutParams pero no estoy seguro de cómo. ¿Alguien podría ayudar a cómo puedo hacer eso? Gracias por adelantado.

Pruebe lo siguiente:

 GoogleMap mGoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById( R.id.map)).getMap(); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100); // I have taken width and hieght 100X100 you can change it as per your need ((SupportMapFragment) getSupportFragmentManager().findFragmentById( R.id.map)).getView().setLayoutParams(layoutParams); 

He probado esto en Nexus 4, esto funcionará con seguridad.

Pruebe esto: 1) En xml: –

  <com.google.android.gms.maps.MapView android:id="@+id/map_view" android:layout_width="fill_parent" android:layout_height="150dip" android:background="@android:color/white" /> 

2) En Actividad: –

  private GoogleMap mMap; private MapView mMapView; private boolean mMapViewExpanded = false; mMapView = (MapView)findViewById(R.id.map_view); mMap = mMapView.getMap(); mMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng point) { animateMapView(); } }); private void animateMapView() { Logging.d(LOG_TAG, "CLICKED ON THE MAPVIEW"); RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mMapView.getLayoutParams(); ResizeAnimation a = new ResizeAnimation(mMapView); a.setDuration(250); if (!getMapViewStatus()) { mMapViewExpanded = true; a.setParams(lp.height, dpToPx(getResources(), 300)); } else { mMapViewExpanded = false; a.setParams(lp.height, dpToPx(getResources(), 150)); } mMapView.startAnimation(a); } private boolean getMapViewStatus() { return mMapViewExpanded; } public int dpToPx(Resources res, int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics()); } 

3) ResizeAnimation.java

 public class ResizeAnimation extends Animation { private int startHeight; private int deltaHeight; // distance between start and end height private View view; /** * constructor, do not forget to use the setParams(int, int) method before * starting the animation * * @param v */ public ResizeAnimation(View v) { this.view = v; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = (int) (startHeight + deltaHeight * interpolatedTime); view.requestLayout(); } /** * set the starting and ending height for the resize animation starting * height is usually the views current height, the end height is the height * we want to reach after the animation is completed * * @param start * height in pixels * @param end * height in pixels */ public void setParams(int start, int end) { this.startHeight = start; deltaHeight = end - startHeight; } /** * set the duration for the hideshowanimation */ @Override public void setDuration(long durationMillis) { super.setDuration(durationMillis); } @Override public boolean willChangeBounds() { return true; } } 

Ejemplo básico utilizando el método onKeyDown() .

 GoogleMap mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { ViewGroup.LayoutParams params = mMap.getView().getLayoutParams(); params.height = 50; mMap.getView().setLayoutParams(params); } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { ViewGroup.LayoutParams params = mMap.getView().getLayoutParams(); params.height = 100; mMap.getView().setLayoutParams(params); } return false; } 
  • Cómo cargar la imagen de la URL de carga de perezosos en Google Maps
  • Android Maps V2 newLatLngBounds con rodamiento
  • Centro de aplicaciones de Google Maps V2 Ubicación actual en pantalla
  • Barra de herramientas no aparece en fragmento con google maps
  • MapView (mapas de android api v2) dentro de la distribución de fragmentos no muestra
  • La mejor forma de volver a crear marcadores / polilíneas cuando se gira el teléfono (cambio de orientación)
  • La ventana de información no es la posición central Android Google Map v2
  • No se pueden recibir las actualizaciones de ubicación de LocationClient después de que la pantalla se apagó
  • Definir ubicación Centro de mapa - GMaps v2 - Android
  • Android Google Map v2 Ejemplo de código
  • Ejecución de Google Maps v2 en el emulador de Android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.