Textviews far apart from edittext android



我不知道为什么Username:和Password:与edittext形式如此之远。有人能帮我修一下吗?

      <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  >
  <TableLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <TableRow
  android:layout_gravity="center"
  android:gravity="center"
  android:layout_marginTop="10dp"
  >
   <TextView 
   android:text="Username : "
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/userset"
   style="@style/regFont"
   />
   <EditText
   android:id="@+id/versionuser"
   android:layout_height="wrap_content"
   android:layout_width="200dp"
   android:layout_toRightOf="@id/userset">
   <requestFocus>
   </requestFocus>
   </EditText>
   </TableRow>
   <TableRow
   android:layout_gravity="center"
   android:gravity="center"
   android:layout_marginTop="5dp"
   >
   <TextView 
   android:text="Password : "
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/passset"
   style="@style/regFont"
   />
   <EditText
   android:id="@+id/versionpass"
   android:layout_height="wrap_content"
   android:layout_width="200dp"
   android:layout_marginTop="5dp"
   android:layout_toRightOf="@id/passset"
   android:inputType="textPassword">
   </EditText>
   </TableRow>
   <TableRow
   android:layout_gravity="center"
   android:gravity="center"
   android:layout_marginTop="5dp"
   >
   <CheckBox
   android:text="Automatic Login"
   android:id="@+id/cbauto"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   </CheckBox>
   </TableRow>
   </TableLayout>
   </RelativeLayout>

这是因为你的CheckBox使用了TableLayout的第一行。所以你的TextView会使用和CheckBox一样的大小。

您应该尝试为CheckBox项创建一个单独的TableLayout,这样它就不会从先前的TableRows中获取宽度,然后将两个TableLayouts放入一个封闭的LinearLayout中,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:orientation="vertical">
  <TableLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  >
  <TableRow
  android:layout_width="fill_parent"
   android:layout_height="wrap_content"
  android:layout_gravity="left"
  android:gravity="left"
  android:layout_marginTop="10dp"
  >
   <TextView 
   android:text="Username : "
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/userset"
   />
   <EditText
   android:id="@+id/versionuser"
   android:layout_height="wrap_content"
   android:layout_width="200dp"
   android:layout_toRightOf="@id/userset">
   <requestFocus>
   </requestFocus>
   </EditText>
   </TableRow>
   <TableRow
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_gravity="left"
   android:gravity="left"
   android:layout_marginTop="5dp"
   >
   <TextView 
   android:text="Password : "
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/passset"
   />
   <EditText
   android:id="@+id/versionpass"
   android:layout_height="wrap_content"
   android:layout_width="200dp"
   android:layout_marginTop="5dp"
   android:layout_toRightOf="@id/passset"
   android:inputType="textPassword">
   </EditText>
   </TableRow>
   </TableLayout>
  <TableLayout android:layout_marginTop="5dp" android:gravity="left" android:layout_height="wrap_content" android:layout_width="fill_parent">
      <CheckBox android:layout_width="wrap_content" android:text="Automatic Login" android:layout_height="wrap_content" android:id="@+id/cbauto"></CheckBox>
  </TableLayout>
</LinearLayout>

最新更新