2012-12-28 3 views
0

J'ai cette disposition linéaire et à l'intérieur de la disposition linéaire j'ai plusieurs vues de texte. Maintenant, ce que je veux faire est d'afficher le texte d'information sur le côté gauche, puis la valeur à côté de lui, mais les valeurs doivent être alignées après le plus long texte d'information.Android UI comment aligner textviews?

Je ne vois pas comment je peux utiliser une autre disposition linéaire dans la disposition linéaire.

  <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:orientation="vertical" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Room:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Date:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Time:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Location" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </LinearLayout> 

comme une table html. Un avec le texte d'information et ensuite le suivant avec la valeur. Les vues de texte avec la valeur de texte doivent être alignées après le texte d'information le plus long.

Html équivalent

<table> 
<tr> 
<td>Room:</td> 
<td>{value}</td> 
</tr> 
<tr> 
<td>Date:</td> 
<td>{value}</td> 
</tr> 
... 
</table> 

Est-il possible d'aligner ce en plus de mettre en une largeur fixe dp?

Répondre

1

Essayez ce code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:background="#0099cc" 
    tools:context=".FullscreenActivity" > 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

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

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Room:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </TableRow> 

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

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Date:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </TableRow> 

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

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Time:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </TableRow> 

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

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Location" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
2

Quelque chose comme ça,

Room: Value 
Date: Value 

Vous pouvez utiliser une mise en page comme ça,

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:orientation="vertical" > 

    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:orientation="horizontal" > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Room:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </LinearLayout> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:orientation="horizontal" > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Date:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </LinearLayout> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:orientation="horizontal" > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Time:" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="Location" 
       android:textSize="12dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff00ff" 
       android:text="{value}" 
       android:textSize="12dp" /> 
     </LinearLayout> 
     </LinearLayout> 

Si vous voulez créer une table comme strucutre, alors vous devriez regarder Table Layout. Vous trouverez un bon exemple here

0

U peut mettre les textViews dans un LinearLayout comme ci-dessous

 <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="5dp" 
       android:layout_marginLeft="5dp" 
       android:orientation="vertical" > 

    <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="#ff00ff" 
        android:text="Room:" 
        android:textSize="12dp" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="#ff00ff" 
        android:text="{value}" 
        android:textSize="12dp" /> 
    </LinearLayout> 

    // add the rest of textviews similarly as above 
</LinearLayout> 
Questions connexes