2016-07-06 1 views
2

AIDE J'utilise TableLayout & TableRow, dans l'image ci-dessous, j'essaie de marges n ° 4 et n ° 6 ensemble tout comme n ° 1 mais je n'avais aucune idée de comment le faire. Pour n ° 1, j'ai pu faire parce que je viens d'utiliser Layout-weight pour diviser l'écran en 3row, 3col.Comment utiliser TableLayout pour créer le design que je veux?

enter image description here

<TableLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:stretchColumns="*"> 
<TableRow 
    android:layout_weight="2" 
    android:id="@+id/tableRow1"> 
    <TextView 
     android:text="1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:background="@android:color/holo_blue_dark" /> 
    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_span="2" 
     android:stretchColumns="*" 
     android:id="@+id/tableLayout1"> 
     <TableRow 
      android:layout_weight="1" 
      android:id="@+id/tableRow1" 
      android:background="@android:color/holo_red_dark"> 
      <TextView 
       android:text="2" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_span="2" 
       android:gravity="center" /> 
     </TableRow> 
     <TableRow 
      android:layout_weight="1" 
      android:id="@+id/tableRow3"> 
      <TextView 
       android:text="3" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="center" /> 
      <TextView 
       android:text="4" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="center" /> 
     </TableRow> 
    </TableLayout> 
</TableRow> 
<TableRow 
    android:layout_weight="1" 
    android:id="@+id/tableRow1"> 
    <TextView 
     android:text="5" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_span="2" 
     android:gravity="center" 
     android:background="@android:color/holo_green_dark" /> 
    <TextView 
     android:text="6" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="right" /> 
</TableRow> 

ci-dessous img est le résultat que je veut enter image description here

+0

consulter ma réponse. Cela devrait vous aider. –

Répondre

1

Utilisez GridLayout. Essayez ce code suivant

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:padding="5dp" 
android:rowCount="3" 
android:columnCount="3" 
android:layout_height="wrap_content"> 


<Button 
android:text="1" 
android:layout_height="wrap_content" 
android:layout_gravity="fill_vertical" 
android:layout_rowSpan="2" 
android:layout_width="wrap_content" 
android:background="#abc012"/> 

<Button 
android:text="2" 
android:layout_columnSpan="2" 
android:layout_gravity="fill_horizontal" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:background="#a01012"/> 
<Button 
android:text="3" 
android:layout_gravity="fill" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:background="#10fa5c"/> 

<Button 
android:text="4" 
android:layout_rowSpan="2" 
android:layout_gravity="fill_vertical" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:background="#9d34a1"/> 

<Button 
android:text="5" 
android:layout_gravity="fill_horizontal" 
android:layout_columnSpan="2" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:background="#f0f53f"/> 

</GridLayout> 

Screen shot

Screenshot

Modifier 1

, remplacez les

android:layout_height="match_parent" 

au lieu de

android:layout_height="wrap_content" 

dans <GridLayout>. Ensuite, vous obtiendrez la sortie en suivre comme,

enter image description here

+0

Salut merci pour votre aide, désolé je suis encore un débutant dans ce domaine, j'essaie de faire horizontalement, définir la hauteur de gridlayout dans match_parent mais l'ajustement de la taille est désordonné je veux est en plein écran et pas d'espaces vides ?? Peut m'apprendre comment le faire? –

+0

voir mon edit1. ça va montrer ce que tu veux –