我想要为Android应用程序创建一个登录界面。我使用了TableLayout来实现正确的对齐方式。因此,两行包括一个TextView和一个EditText,并且我想在它们下面添加一个宽度拉伸到屏幕的按钮。所以我把按钮放在另一个TableRow中,并在Button上添加layout_span="2",但是按钮显示在第一列。
我认为这应该是正确的,但我在xml文件中做错了什么。你有什么想法吗?
我认为这应该是正确的,但我在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>
提前感谢您!