Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing android error "Invalid layout param"

Tags:

android

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> 
like image 900
Kharl Mccatty Avatar asked Apr 29 '26 10:04

Kharl Mccatty


1 Answers

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 >
like image 195
Rod_Algonquin Avatar answered Apr 30 '26 22:04

Rod_Algonquin