开发者

Textviews far apart from edittext android

开发者 https://www.devze.com 2023-03-26 18:22 出处:网络
I don\'t know why Username: and Password: is so far apart from the edittext forms. Can someone help me fix this?

I don't know why Username: and Password: is so far apart from the edittext forms. Can someone help me fix this?

      <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"开发者_StackOverflow中文版
   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>


It's because your CheckBox use the first row of your TableLayout. So your TextView will use the same size of your CheckBox.

You should try making a separate TableLayout for the CheckBox item so that it does not take the widths from the earlier TableRows, and then put both TableLayouts into an enclosing LinearLayout, like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消