Centre Android GridLayout horizontalement
Je suis en train de créer un GridLayout avec 2 colonnes qui sera centré.
Mon avtual design est:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:rowCount="4"
custom:columnCount="2"
android:orientation="horizontal">
<TimeTableKeeper.Tile
android:layout_width="75dp"
android:layout_height="75dp"
android:gravity="top|left"
android:background="#00FF00"
custom:color="green"
custom:layout_row="0"
custom:layout_column="0" />
<TimeTableKeeper.Tile
android:layout_width="75dp"
android:gravity="top|left"
android:layout_height="75dp"
android:background="#00FF00"
custom:color="blue"
custom:layout_row="0"
custom:layout_column="1" />
</GridLayout>
Et il ressemble:
Et je voudrais avoir ce bouton, au centre et à la perfection avec un espacement entre eux.
Est-il possible?
--EDIT:
J'ai aussi essayé de mettre en LinearLayout, sans résultats:
<?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:gravity="center"
android:orientation="vertical">
<GridLayout xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:rowCount="4"
custom:columnCount="2"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center">
<TimeTableKeeper.Tile
android:layout_width="75dp"
android:layout_height="75dp"
android:background="#00FF00"
custom:color="green"
custom:layout_row="0"
custom:layout_column="0" />
<TimeTableKeeper.Tile
android:layout_width="75dp"
android:layout_height="75dp"
android:background="#00FF00"
custom:color="blue"
custom:layout_row="0"
custom:layout_column="1" />
</GridLayout>
</LinearLayout>
source d'informationauteur Tomasz
Vous devez vous connecter pour publier un commentaire.
La grille enrouler autour de son contenu horizontalement avec
layout_width="wrap_content"
et de l'ensemble delayout_gravity
àcenter
:De GridLayout documentation:
(...)
Donc, apparemment, vous devez définir la
layout_gravity
àandroid:layout_gravity="top|center"
(je n'ai pas testé, mais à partir de la documentation, il devrait être le long de ces lignes.)Vous y êtes presque. Je pense que cela va faire la job:
copie de cet exemple pour calculatrice layout =)