2012-09-18 4 views
2

Bonjour, j'ai des problèmes avec l'image ci-dessous. Comme vous pouvez le voir, les rangées de tables prennent tellement d'espace et je voudrais les réduire car il y a d'autres widgets de vue sous eux. Comment puis-je atteindre cet objectif? Je vous remercie.TableRow prendre plus d'espace que d'habitude android TableLayout

enter image description here

ceci est mon xml:

<?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:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="3" 
    android:padding="8dp" 
    android:background="@drawable/rounded_date_filter"> 

    <TableRow 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

<TextView 
    android:id="@+id/datefilter_text_from_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" 
    android:text="@string/from_text"> 
</TextView> 
<TextView 
    android:id="@+id/datefilter_text_to_id" 
    android:layout_width="10dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_marginLeft="40dp" 
    android:layout_marginTop="10dp" 
    android:text="01-01-2012"> 
</TextView> 
</TableRow> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1px" 
     android:background="#606060"> 
    </View> 

<TableRow> 
<TextView 
    android:id="@+id/datefilter_text_from_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" 
    android:text="@string/to_text"> 
</TextView> 

<TextView 
    android:id="@+id/datefilter_text_to_id" 
    android:layout_width="10dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_marginLeft="40dp" 
    android:layout_marginTop="10dp" 
    android:text="01-09-2012"> 
</TextView> 
</TableRow> 

     <View 
     android:layout_width="fill_parent" 
     android:layout_height="1px" 
     android:background="#606060"> 
    </View> 

    <TableRow> 
<TextView 
    android:id="@+id/datefilter_text_from_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" 
    android:text="@string/groupby"> 
</TextView> 

<TextView 
    android:id="@+id/datefilter_text_to_id" 
    android:layout_width="10dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_marginLeft="40dp" 
    android:layout_marginTop="10dp" 
    android:text="day"> 
</TextView> 
</TableRow> 

</TableLayout> 

    <Button 
     android:id="@+id/reset_filter_button_id" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/reset_filters"> 
    </Button> 
</LinearLayout> 
+0

Retirez le poids de mise en page de la 'TableRows'. – Luksprog

+0

@Luksprog désolé pour la réponse tardive. J'ai fait cela mais cela n'aide pas – irobotxxx

Répondre

1

J'ai testé votre disposition et à la fin il semble que les weightSum et layout_weight ne sont pas responsables. Définir le TableLayout pour envelopper le contenu et le layout_weight sur le TextViews semble étendre le TableLayout et lui donner le comportement que vous voyez.

Si vous définissez la largeur des TableLayout à FILL_PARENT les problèmes devraient disparaître:

// ... 
<TableLayout 
    android:layout_width="fill_parent" 
// ... 

Cela fait en quelque sorte le sens que vous essayez d'utiliser le poids de mise en page lorsque le parent n'a pas vraiment d'espace pour épargner (à cause du wrap_content), rien de bon ne peut en découler.

En outre, si c'est tout votre mise en page, vous pouvez l'améliorer et ajouter le Button directement au TableLayout (dans un autre TableRow) supprimant la nécessité pour l'emballage LinearLayout.

+0

Merci pour cela. votre solution fonctionne. J'ai également découvert que je pourrais le réduire en définissant l'attribut maxHeight pour les TextViews mais votre solution est plus propre je pense. Aussi je veux avoir une TableLayout arrondie, donc le bouton ne peut pas être dans le TableLayout. – irobotxxx

+0

puis-je utiliser cette opportunité pour demander comment faire un TableLayout arrondi? .. je sais que vous pouvez définir un dessin avec rectangle de forme et une couleur et l'utiliser comme arrière-plan. mais je ne veux pas que l'arrière-plan ait une couleur quelconque, je veux juste que les lignes \ border du rectangle soient visibles. une idée de comment faire ça? – irobotxxx

+0

@sparrow Je ne suis pas sûr de comprendre.Voulez-vous conserver l'actuel drawable que vous utilisez comme arrière-plan pour 'TableLayout' et aussi avoir des bordures arrondies autour de' TableLayout'? – Luksprog

0

Le layout_weight est utilisé pour indiquer la mise en page pour remplir l'espace avec force. Dans la disposition ci-dessus, le poids de TableRow est spécifié en tant que 1 et weighSum en tant que 3. Supprimez le poids de la disposition et le poids. Cela fonctionnera.

+0

cela ne fonctionne toujours pas quand je fais cela. – irobotxxx

0

Voici le fichier de mise en page corrigé:

<?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:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="8dp" 
     android:weightSum="3" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/datefilter_text_from_id" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="From" > 
      </TextView> 

      <TextView 
       android:id="@+id/datefilter_text_to_id" 
       android:layout_width="10dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="40dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:text="01-01-2012" > 
      </TextView> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

      <View 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:layout_weight="1" 
       android:background="#606060" > 
      </View> 
     </TableRow> 

     <TableRow> 

      <TextView 
       android:id="@+id/datefilter_text_from_id" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="To" > 
      </TextView> 

      <TextView 
       android:id="@+id/datefilter_text_to_id" 
       android:layout_width="10dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="40dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:text="01-09-2012" > 
      </TextView> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

      <View 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:layout_weight="1" 
       android:background="#606060" > 
      </View> 
     </TableRow> 

     <TableRow> 

      <TextView 
       android:id="@+id/datefilter_text_from_id" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="Group By" > 
      </TextView> 

      <TextView 
       android:id="@+id/datefilter_text_to_id" 
       android:layout_width="10dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="40dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:text="day" > 
      </TextView> 
     </TableRow> 
    </TableLayout> 

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

</LinearLayout> 

et la mise en page de sortie:

enter image description here

Les problèmes que je constate et que par conséquent corrigées sont:

  • Ajouté Le row separation comme une ligne distincte, au lieu de vue ambigu de TableLayout
  • Changé la layout_width de TableLayoutwrap_content-fill_parent
Questions connexes