Invalid layout param

1.9k Views Asked by At

I'm getting the following errors and can't work out what the problem is.

  • Invalid layout param in a relativelayout: layout_centerHorizontal
  • Invalid layout param in a relativelayout: layout_alignParentTop

The code that has these errors is:

<textview android:id="@+id/textView"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_gravity="center"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:text="@string/welcome"
          android:textColor="#000000">

Thanks.

EDIT: The whole layout file code-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/android"
android:orientation="vertical" >

<TextView android:id="@+id/textView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/welcome" android:textColor="#000000">
<EditText android:hint="@string/email" android:id="@+id/email" android:layout_alignParentRight="true" android:layout_below="@+id/textView" android:layout_height="40dp" android:layout_width="200dp" android:textColor="#000000" android:textSize="15dp">
<Button android:id="@+id/login" android:layout_alignParentRight="true" android:layout_alignTop="@+id/registerbtn" android:layout_height="40dp" android:layout_width="170dp" android:text="@string/login" android:textColor="#000000" android:textSize="13dp">
</Button><Button android:id="@+id/registerbtn" android:layout_below="@+id/pword" android:layout_height="40dp" android:layout_marginTop="10dp" android:layout_toLeftOf="@+id/login" android:layout_width="220dp" android:text="@string/register" android:textColor="#000000" android:textSize="13dp">
<TextView android:id="@+id/loginErrorMsg" android:layout_alignParentLeft="true" android:layout_below="@+id/passres" android:layout_height="56dp" android:layout_width="fill_parent" android:textColor="#000000">
<TextView android:id="@+id/textView2" android:layout_alignTop="@+id/email" android:layout_height="40dp" android:layout_toLeftOf="@+id/textView" android:layout_width="200dp" android:text="@string/email" android:textColor="#000000" android:textSize="15dp">
<EditText android:ems="10" android:hint="@string/password" android:id="@+id/pword" android:inputType="textPassword" android:layout_alignLeft="@+id/email" android:layout_below="@+id/email" android:layout_height="40dp" android:layout_width="200dp" android:textColor="#000000" android:textSize="15dp">
<TextView android:id="@+id/pworda" android:layout_alignBottom="@+id/pword" android:layout_alignRight="@+id/textView2" android:layout_height="40dp" android:layout_width="200dp" android:text="@string/password" android:textColor="#000000" android:textSize="15dp">
</TextView></EditText></TextView></TextView></Button><Button android:id="@+id/passres" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/login" android:layout_height="40dp" android:layout_width="wrap_content" android:text="@string/forgot_password" android:textColor="#000000" android:textSize="13dp">

2

There are 2 best solutions below

2
On

This XML is not even well-formed, lots of elements have a starting tag, and no end tag. For example, instead of <TextView> you should write <TextView></TextView>, or, better, <TextView/>. Fix that, and check the errors again.

0
On
  1. you have no closing tag for Relative Layout (add </RelativeLayout> at the end)
  2. Your Views are in a complete mess, try to clean format your code and you will see following:

``

 <TextView ...>
        <EditText ...>
            <Button ...>
            </Button>
            <Button ...>
                <TextView ....>
                     <TextView ...>
                           <EditText ...>
                                 <TextView ...>
                                 </TextView>
                           </EditText>
                     </TextView>
                </TextView>
            </Button>
            <Button ...>

You are trying to warp textviews inside edittexts and buttons and so forth... that wont work. try following:

<TextView ... />
<EditText ... />
...