2013-01-08 46 views
7

我想創建一個登錄屏幕的Android應用程序。我正在使用TableLayout以獲得正確的對齊方式。因此,兩行由一個TextViewEditText的,我想補充低於他們Button該寬度拉伸到屏幕上。所以我把Button在另一個TableRow和我說layout_span="2"Button,但Button顯示在第一列。layout_span在TableLayout在Android的

我想這應該是正確的,但我必須做一些錯誤的XML文件。你知道什麼是錯的嗎?

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

在此先感謝!

回答

3

最後我在一個LinearLayout包裹着我TableLayout和我TableLayout後加入Button

<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

在原始的XML文件,你可以簡單地添加

機器人:layout_weight = 「1」

在您的按鈕