Kharl Mccatty
Kharl Mccatty

Reputation: 45

Fixing android error "Invalid layout param"

Hey Im fairly new to android programming and I have several errors in my code. I know there were similar errors i searched for it but none particular to my specific code.

The specific lines with its particular errors are as follows:

android:layout_alignLeft="@+id/edit_message"-Invalid layout param in a Editext:layout_align_left

android:layout_below="@+id/edit_message"-Invalid layout param in a Editext:layout_below

android:layout_alignBottom="@+id/editText1"-Invalid layout param in a Editext: android:layout_alignParentRight="true"-Invalid layout param in a Editext:

Here is all of my code,please tell me what part I need to correct to fix the error.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.discountprice2.MainActivity$PlaceholderFragment" >
    <EditText
    android:id="@+id/edit_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="@string/edit_message"
    android:inputType="text|number" >

        <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/edit_message"
    android:layout_below="@+id/edit_message"
    android:ems="10"
    android:hint="@string/edit_message1"
    android:inputType="numberDecimal" />

        <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:onClick="sendMessage"
    android:text="@string/calc" />
    </EditText>
    </LinearLayout> 

Upvotes: 3

Views: 11230

Answers (6)

Sivaram
Sivaram

Reputation: 43

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
    <LinearLayout
        android:id="@+id/Leadlayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginStart="@dimen/activity_horizontal_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginBottom="8dp"
        android:orientation="horizontal"
        android:padding="10dp"
        android:weightSum="1">

        <Button
            style="@style/Widget.MaterialComponents.Button"
            android:id="@+id/Leadbutton1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginStart="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="0.5"
            android:gravity="center"
            android:onClick="saveButton"
            android:text="SAVE"
            android:textColor="@color/colorwhite"
            android:textSize="16sp"
            android:textStyle="bold" />

        <Button
            style="@style/Widget.MaterialComponents.Button.TextButton"
            android:id="@+id/Leadbutton2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="0.5"
            android:background="@drawable/oval"
            android:gravity="center"
            android:onClick="clearButton"
            android:text="CLEAR"
            android:textColor="@color/colorblue"
            android:textSize="16sp"
            android:textStyle="bold" />

    </LinearLayout>
</RelativeLayout>

Upvotes: 0

Aniruddha
Aniruddha

Reputation: 4487

The following are not the attributes of LinearLayout, they belong to RelativeLayout

android:layout_alignLeft="@+id/edit_message"

android:layout_below="@+id/edit_message"


android:layout_alignBottom="@+id/editText1"


android:layout_alignParentRight="true"

Change your main layout to ReativeLayout

Please go through RelativeLayout and LinearLayout

EDIT

Replace

<EditText
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/edit_message"
android:inputType="text|number" >

    <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edit_message"
android:layout_below="@+id/edit_message"
android:ems="10"
android:hint="@string/edit_message1"
android:inputType="numberDecimal" />

    <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentRight="true"
android:onClick="sendMessage"
android:text="@string/calc" />
</EditText>

with

<EditText
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/edit_message"
android:inputType="text|number" >
</EditText>
    <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edit_message"
android:layout_below="@+id/edit_message"
android:ems="10"
android:hint="@string/edit_message1"
android:inputType="numberDecimal" />

    <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentRight="true"
android:onClick="sendMessage"
android:text="@string/calc" />

Your first EditText ended at the last, i.e. after Button. It should be closed like above.

Upvotes: 1

Devrath
Devrath

Reputation: 42834

Possible solutions ::

  1. Change your Linear layout to relative layout
  2. Remove the invalid params from the design if you need linear layout

Note :: Always clean and build your project if you still see the errors

Upvotes: 1

Alok Nair
Alok Nair

Reputation: 4004

layout_alignLeft makes the left edge of your view match the left edge of the view whose ID you use as the parameters.

layout_toLeftOf makes your view placed to the left side of the view whose ID you use (the right edge will be aligned with the left edge of the other view).

For other relative layout params visit here :

http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

The parameters you have used are for relative layout and not Linear Layout. Change Linear layout to Relative layout.

Upvotes: 0

Hanish Sharma
Hanish Sharma

Reputation: 869

Use Relative Layout instead of Linear Layout

Upvotes: 0

Rod_Algonquin
Rod_Algonquin

Reputation: 26198

That is because android:layout_alignLeft, android:layout_below, etc. are only bounded to the RelativeLayout not in LinearLayout, LinearLayout has only two orientation which is vertical and horizontal it does not support layout alignment for each Views.

solution:

change your parent layout to RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.discountprice2.MainActivity$PlaceholderFragment" >

         /////////YOUR CONTENT HERE///////////////

</RelativeLayout >

Upvotes: 8

Related Questions