4

I am getting the below error for my android layout file in Eclipse editor :

Invalid layout param in a RelativeLayout: layout_weight

Layout :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <EditText
        android:id="@+id/text_input"    
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_weight="0.7"
        />

    <EditText
        android:id="@+id/text_input1"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_toRightOf="@id/text_input"
        />

</RelativeLayout>

What's wrong with my layout_weight ?

canova
  • 3,965
  • 2
  • 22
  • 39
faizal
  • 3,497
  • 7
  • 37
  • 62

2 Answers2

4

Relative layout does not support weight.

Linearlayout support it. You can use Linearlayout like below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="Horizontal">

    <EditText
        android:id="@+id/text_input"    
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_weight="0.7"
        />

    <EditText
        android:id="@+id/text_input1"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        />
</LinearLayout>
Jude Niroshan
  • 4,280
  • 8
  • 40
  • 62
Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44
  • Thank you. I used android:layout_width="0dp" and android:layout_weight="0.3" for the second EditText. – faizal May 22 '14 at 05:56
0

layout_weight used for Parent LinearLayout but here your parent layout is RelativeLayout. So you can't use it.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="Horizontal">

    <EditText
        android:id="@+id/text_input"    
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        android:layout_weight="0.7"
        />

    <EditText
        android:id="@+id/text_input1"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:inputType="textMultiLine"
        android:background="@drawable/bg_textinput"
        />
</LinearLayout>
Piyush
  • 18,895
  • 5
  • 32
  • 63