2010-08-04 5 views
0

J'essaie de créer des tables avec des coins arrondis. J'ai un peu de XML pour le faire, mais j'ai un problème. La table enveloppe elle-même la largeur de son texte interne. Je veux que la chose entière remplisse le parent (bien que je veux une bordure autour de lui donc il y a un coussin, que j'ai). Je ne peux pas comprendre pourquoi ce n'est pas quand j'ai tout à fill_parent. Quelqu'un pourrait-il indiquer ce qui ne va pas?Problème avec une interface utilisateur avancée

Voici une capture d'écran de ce que je veux dire et une copie de mon XML:

screenshot 1

shape_outer.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#0000FF"/> 
    <corners android:radius="5px"/> 
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape> 

shape_inner.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <corners android:radius="5px"/> 
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape> 

ma mise en page:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="47px" 
     style="?android:attr/windowTitleBackgroundStyle" 
     android:gravity="center"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="My title" 
      style="?android:attr/windowTitleStyle" 
      android:paddingLeft="5px" /> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:padding="10px" 
     > 
     <!-- used so we can separate two tables --> 
     <TableLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:stretchColumns="1" 
      > 
      <!-- first table --> 
      <TableRow android:paddingBottom="10px"> 
       <!-- outer border --> 
       <TableLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:stretchColumns="1" 
        android:padding="2px" 
        android:background="@drawable/shape_outer" 
        > 
        <TableRow> 
         <!-- inner whitespace --> 
         <TableLayout 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:stretchColumns="1" 
          android:layout_weight="1" 
          android:background="@drawable/shape_inner" 
          android:padding="10px" 
          > 
          <TableRow> 
           <!-- first row: one --> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="One:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/one" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="sadflkjaasasdfadsdsf;lkjdsal;asdj" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:maxLines="1" /> 
           </LinearLayout> 
          </TableRow> 
          <!-- separator --> 
          <View 
           android:layout_height="1dip" 
           android:background="#FF909090" /> 
          <TableRow> 
           <!-- second row: two --> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="Two:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/two" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="asdfasdasdfasdfasfasdfasgeargfsgsfd" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:maxLines="1" /> 
           </LinearLayout> 
          </TableRow> 
         </TableLayout> 
        </TableRow> 
       </TableLayout> 
      </TableRow> 
      <!-- second table --> 
      <TableRow> 
       <!-- outer border --> 
       <TableLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:stretchColumns="1" 
        android:padding="2px" 
        android:background="@drawable/shape_outer" 
        > 
        <TableRow> 
         <!-- inner white space --> 
         <TableLayout 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:stretchColumns="1" 
          android:background="@drawable/shape_inner" 
          android:padding="10px" 
          > 
          <!-- third row: Three --> 
          <TableRow> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="Three:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/three" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="asdfasfasdfasgeargfsgsfd" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:singleLine="true" 
             android:ellipsize="end" /> 
           </LinearLayout> 
          </TableRow> 
          <!-- separator --> 
          <View 
           android:layout_height="1dip" 
           android:background="#FF909090" /> 
          <!-- second row: four --> 
          <TableRow> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="Four:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/four" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="aasdfasfasdfasgeargfsgsfd" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:singleLine="true" 
             android:ellipsize="end" /> 
           </LinearLayout> 
          </TableRow> 
         </TableLayout> 
        </TableRow> 
       </TableLayout> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 
</LinearLayout> 
+0

On dirait que vous avez une mise en page vraiment compliquée .. Le HeirarchyViewer, trouvé dans le dossier des outils, pourrait vous aider à déboguer. Vous pouvez chercher à voir quel élément fait que votre rangée s'étend au-delà de l'endroit où vous le voulez. –

+0

Merci pour votre réponse. Ce n'est pas seulement que cela provoque l'extension de la table au-delà des limites de l'écran. Si le texte est très court, la table car très étroite aussi. Mais il ne devrait pas y avoir d'emballage :( – Andrew

+0

Je semble l'avoir corrigé, bien que je ne comprenne pas pourquoi: Mon TableLayout le plus à l'extérieur est maintenant fill_parent, alors que tous les autres Table_Layout sont wrap_content Merci encore – Andrew

Répondre

0

L'utilisation de tables était compliquée et inutile. Voici mon XML de travail:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="10dip" 
    android:paddingBottom="10dip" 
    android:paddingLeft="15dip" 
    android:paddingRight="15dip" 
    > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="2dip" 
     android:background="@drawable/shape_outer" 
     > 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/shape_inner" 
      > 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="left|center_vertical" 
       android:padding="10dip" 
       > 
       <TextView 
        android:layout_width="70dip" 
        android:layout_height="wrap_content" 
        android:text="One:" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:gravity="right" /> 
       <TextView 
        android:id="@+id/one" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:text="sdklafjalfkjaslgkjafds" 
        android:maxLines="1" 
        android:ellipsize="end" /> 
      </LinearLayout> 
      <View 
       android:layout_height="1dip" 
       android:layout_width="fill_parent" 
       android:background="#FF909090" 
       android:padding="10dip" /> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="left|center_vertical" 
       android:padding="10dip" 
       > 
       <TextView 
        android:layout_width="70dip" 
        android:layout_height="wrap_content" 
        android:text="Two:" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:gravity="right" /> 
       <TextView 
        android:id="@+id/two" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:text="dsaklfajsdkldsafjsf" 
        android:maxLines="1" 
        android:ellipsize="end" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
1

content que vous l'ayez corrigé, mais vous pourriez obtenir le même aspect beaucoup plus facilement en utilisant des mises en page relatives.

+0

Comment alors? Je devrais alors positionner les formes et les textviews les uns sur les autres Cela ne serait-il pas un niveau de complexité supplémentaire? – Andrew

+0

Voici la partie la plus difficile: Je voudrais que ces tables soient dynamiques, ce qui veut dire que dans mon code Java, je voudrais pouvoir les ajouter pour N choses Est-il possible de réaliser ceci? La seule chose que je peux penser est d'utiliser un ListView avec un Le problème est que je ne veux pas que les tables soient au maximum à 2 lignes, je veux aussi que ces lignes soient dynamiques. – Andrew

Questions connexes