2013-01-08 14 views
7

Vorrei creare una schermata di accesso per un'applicazione Android. Sto usando TableLayout per ottenere l'allineamento corretto. Quindi due righe consistono in un TextView e un EditText e vorrei aggiungere uno Button sotto di loro che la larghezza è allungata sullo schermo. Così ho inserito lo Button in un altro TableRow e ho aggiunto layout_span="2" per lo Button, ma lo Button viene visualizzato nella prima colonna.layout_span in TableLayout in Android

Penso che questo dovrebbe essere corretto, ma devo fare qualcosa di sbagliato nel file xml. Hai un'idea di cosa c'è che non va?

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context=".LoginActivity" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:paddingRight="15dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="@string/evUsername" /> 
     <EditText 
      android:id="@+id/username" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:inputType="text" /> 
    </TableRow> 
    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:paddingRight="15dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="@string/evPassword" /> 
     <EditText 
      android:id="@+id/password" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:inputType="textPassword" /> 
    </TableRow> 
    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <Button 
      android:id="@+id/btnLogin" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_span="2" 
      android:text="@string/btnLogin" /> 
    </TableRow> 
</TableLayout> 

Grazie in anticipo!

risposta

3

Alla fine ho avvolto il mio TableLayout in un LinearLayout e ho aggiunto il Button dopo il TableLayout.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context=".LoginActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:paddingRight="15dp" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="@string/evUsername" /> 
      <EditText 
       android:id="@+id/username" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:inputType="text" /> 
     </TableRow> 
     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:paddingRight="15dp" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="@string/evPassword" /> 
      <EditText 
       android:id="@+id/password" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:inputType="textPassword" /> 
     </TableRow> 
    </TableLayout> 
    <Button 
     android:id="@+id/btnLogin" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/btnLogin" /> 
</LinearLayout> 
3

nel file XML originale, si può semplicemente aggiungere

android: layout_weight = "1"

nel vostro pulsante

Problemi correlati