Android – ¿Cómo dividir una vista en 4 partes iguales?

Me gustaría tomar una pantalla, dividirlo en cuatro cuadrados en diferentes colores y adjuntar un oyente de clic a ellos.

Mi pregunta es cómo dividir la pantalla a 4 cuadrados iguales.

¡Gracias por adelantado!

Dvir

Aquí hay un diseño con 4 botones con diferentes colores:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.0" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:layout_weight="1.0" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_green_light" android:layout_weight="1.0" android:text="Button" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.0" android:orientation="horizontal" > <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_blue_light" android:layout_weight="1.0" android:text="Button" /> <Button android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_red_light" android:layout_weight="1.0" android:text="Button" /> </LinearLayout> </LinearLayout> 

Introduzca aquí la descripción de la imagen

El código siguiente dividirá su pantalla en cuatro partes.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > </LinearLayout> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > </LinearLayout> </LinearLayout> 

Utilice cualquier "vista" en lugar de "LinearLayout", pero con el uso de sus atributos en ese.

  • ¿Existe alguna manera de mostrar la insignia de notificación en los elementos de menú BottomNavigationView oficiales de Google que se incluyen en la API 25?
  • La escala de una vista reduce el tamaño del contenido pero aumenta los márgenes en blanco
  • Android.content.res.Resources $ NotFoundException para ic_sync_black_24dp.xml
  • La señal de Seterror no está desapareciendo y la Búsqueda está funcionando
  • Dibujo de lienzo que no se dibuja correctamente a pesar de las propiedades de configuración
  • SwipeRefreshLayout detecta un evento de desplaza hacia abajo antes de iniciar onRefresh ()
  • Android diseño de diseño - Cómo obtener la altura de la pantalla en xml (layouts)
  • ScrollView no se desplaza hasta el final del margen inferior del LinearLayout interno
  • ¿Cuál es la diferencia entre match_parent y fill_parent?
  • ¿Cómo alinear linearlayout al centro vertical?
  • Cómo ocultar vistas parcialmente visibles en Android xml layout sin código?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.