2011-03-31 12 views
5

Estoy tratando de dividir una pantalla en 2 secciones. La sección de arriba es un widget de mapa. A continuación hay otro diseño lleno de widgets. El problema es que el widget de mapa llena toda la pantalla. ¿Cómo puedo hacer que el diseño debajo del mapa empuje el mapa hacia arriba?Android Prioridad de diseño

Supongo que podría resolverse dando al widget del mapa una altura, pero eso no es muy flexible.

Mi attemp:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 



    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:apiKey="my api key" /> 





    <RelativeLayout 
     android:id="@+id/map_menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/mapview" 
     android:background="@drawable/locatie_background" > 


     <Button android:id="@+id/firstButtonId" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="@string/action_ready" 
      /> 

    </RelativeLayout > 

</RelativeLayout> 
+0

Pruebe esto: android: layout_weight = "1" en RelativeLayout. Creo que va a resolver su problema –

+0

@Kartik No, no lo hará. 'layout_weight' es ignorado por' RelativeLayout'. –

+0

Gracias por la sugerencia. Intenté cambiar el diseño principal a linearLayout para poder asignar un peso al segundo diseño relativo. Pero está dando el mismo resultado – Vincent

Respuesta

1

En lugar de RelativeLayout utilizar LinearLayout así:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 


<LinearLayout 
    android:id="@+id/map_menu1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    > 

    <com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:clickable="true" 
    android:apiKey="my api key" /> 
</LinearLayout > 

<LinearLayout 
    android:id="@+id/map_menu" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    > 

    <Button android:id="@+id/firstButtonId" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="action_ready" 
     /> 

</LinearLayout > 

</LinearLayout> 
+0

Gracias, esto es lo que estoy buscando – Vincent

+4

Técnicamente es correcto, pero el innecesario segundo 'LinearLayout' valió -1. –

+0

@karthi octavian tiene razón ... memoria extra .. –

1

reemplace el código con lo siguiente:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 



<com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:apiKey="my api key" /> 





<RelativeLayout 
    android:id="@+id/map_menu" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/mapview" 
    android:background="@drawable/locatie_background" > 


    <Button android:id="@+id/firstButtonId" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="@string/action_ready" 
     /> 

</RelativeLayout > 

</LinearLayout> 
+0

Esto no va a funcionar. –

+0

Funcionará ... Lo comprobé – Udaykiran

+0

Me equivoqué, supongo. Lo siento. –

4

Ir con un LinearLayout, establece la layout_height tanto de los niños a wrap_content y establecer el layout_weight de ambos para 1.

Esto sería dividir la altura pantallas de igual:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:clickable="true" 
     android:apiKey="my api key" /> 
    <RelativeLayout 
     android:id="@+id/map_menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_below="@id/mapview" 
     android:background="@drawable/locatie_background"> 
     <Button android:id="@+id/firstButtonId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/action_ready" /> 
    </RelativeLayout > 
</LinearLayout> 

se puede trabajar con layout_weight como si fueran a ser los valores de porcentaje como aquí:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="90" 
     android:clickable="true" 
     android:apiKey="my api key" /> 
    <RelativeLayout 
     android:id="@+id/map_menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:layout_below="@id/mapview" 
     android:background="@drawable/locatie_background"> 
     <Button android:id="@+id/firstButtonId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/action_ready" /> 
    </RelativeLayout > 
</LinearLayout> 
+1

Cuando termino esto obtengo un error: No se permiten tipos enteros (en 'layout_height' con valor '0'). – Vincent

+0

Corregí mi error. –

+0

Tengo otra pregunta sobre esto. Intenté poner 10 botones en el segundo diseño en lugar de 1, pero parece que el diseño no se puede proyectar más que la altura de su fondo. ¿Esto es normal? – Vincent