2013-01-08 14 views
7

Android uygulaması için bir giriş ekranı oluşturmak istiyorum. Doğru hizalamayı almak için TableLayout kullanıyorum. Yani iki satır bir TextView ve bir EditText oluşur ve ben genişliğini ekrana gerilir altında bir Button eklemek istiyorum. Bu yüzden Button'u başka bir TableRow'a koydum ve için layout_span="2" ekledim, ancak Button ilk sütunda görüntülenir.layout_span Tabloda ÖdemeLock'ta

Bunun doğru olması gerektiğini düşünüyorum, ancak xml dosyasında yanlış bir şey yapmalıyım. Neyin yanlış olduğuna dair bir fikrin var mı?

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

Şimdiden teşekkürler!

cevap

3

Sonunda TableLayout benim LinearLayout içinde sardım ve TableLayout sonra Button ekledim.

orijinal xml dosyasında
<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

, sadece

android ekleyebilirsiniz: senin düğmesini layout_weight = "1"