2013-01-08 11 views
7

Chciałbym stworzyć ekran logowania do aplikacji na Androida. Używam TableLayout, aby uzyskać prawidłowe wyrównanie. Więc dwa wiersze składają się z TextView i EditText i chciałbym dodać poniżej Button, że szerokość jest rozciągnięta na ekran. Więc wstawiłem Button w innym TableRow i dodałem layout_span="2" dla Button, ale Button jest wyświetlany w pierwszej kolumnie.layout_span w TableLayout w Androidzie

Myślę, że to powinno być prawidłowe, ale muszę zrobić coś nie tak w pliku xml. Czy masz pojęcie, co jest nie tak?

<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> 

Z góry dziękuję!

Odpowiedz

3

Na koniec owinął mój TableLayout w LinearLayout i dodałem Button po 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

W oryginalnym pliku xml, można po prostu dodać

android: layout_weight = "1"

w przycisk

Powiązane problemy