2011-10-28 7 views
0

Je suis nouveau sur Android donc pas très bon avec la mise en page GUi encore. Je construis une interface graphique pour mon application et je n'arrive pas à la faire fonctionner comme je le souhaite. Ce dont j'ai besoin, c'est 4 boutons en bas de l'écran empilés horizontalement. Au-dessus des boutons, j'ai placé un SurfaceView que je veux remplir le reste de l'écran. Le résultat devrait être quelque chose comme ça (j'espère que cela est clair):
Android - mise en page GUI

----------------- 
-    - 
-    - 
-    - 
-    - 
- SurfaceView - 
-    - 
-    - 
-    - 
----------------- 
--- --- --- --- 
-B- -B- -B- -B- 
--- --- --- --- 

Le closeset je suis arrivé était le suivant:

<?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="fill_parent" 
    android:orientation="vertical" > 
    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 
      <SurfaceView 
       android:id="@+id/surfaceView1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
     </TableRow> 
     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 
      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 
       <Button 
        android:id="@+id/button2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
      </LinearLayout> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

Quels sont les résultats malheureusement quelque chose comme ceci:

----------------- 
- SurfaceView - 
----------------- 
--- --- --- --- 
-B- -B- -B- -B- 
--- --- --- --- 

Répondre

2
<?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="fill_parent" 
    android:orientation="vertical" > 


      <SurfaceView 
       android:id="@+id/surfaceView1" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight = "1" 
      /> 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 
       <Button 
        android:id="@+id/button2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
       <Button 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Button" /> 
      </LinearLayout> 

</LinearLayout> 

Essayez ceci. Layout_weight est une étiquette qui fonctionne sur les enfants de la mise en page linéaire.

les enfants partageront la mesure de l'orientation en fonction du poids si elle est mentionnée. Dans votre cas, puisque la disposition linéaire est verticale, ils partageront la hauteur si les poids sont mentionnés. Le poids par défaut de linearLayout est 1, donc si vous donnez 1 à l'un des enfants, il prend l'espace restant. Et disons que le parent a 2 enfants et que leur poids est de 0.6 et 0.4, le premier enfant occupera 60% de la taille du parent et le reste 40% du deuxième enfant.

+0

Merci, cela a fonctionné. Je vais accepter cela dès que le site me le permettra. Pouvez-vous s'il vous plaît expliquer comment vous utilisez ces attributs: android: layout_height = "0dp" android: layout_weight = "1" – Yoav

+1

vérifier ma réponse éditée. –

+0

Merci encore.12 – Yoav

0

Essayez d'utiliser une mise en page relative pour la mise en page la plus haute, et utilisez alignParentBottom pour la disposition de votre barre de boutons.