Bilal Haider
Bilal Haider

Reputation: 495

Relativelayout not wrapping its content

I want my inner RelativeLayout to wrap it's content and stay below the View element. Why isn't it behaving like the pic below?

My layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <View
        android:id="@+id/linearLayout"
        android:layout_above="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <RelativeLayout
        android:id="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#ebebeb">

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_toLeftOf="@+id/imageView13"
            android:layout_toStartOf="@+id/imageView13"
            android:background="@android:color/white"
            android:padding="8dp" />

        <ImageView
            android:id="@+id/imageView13"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_m_send" />

    </RelativeLayout>

</RelativeLayout>

enter image description here

Upvotes: 5

Views: 4366

Answers (2)

Binesh Kumar
Binesh Kumar

Reputation: 2860

use this way

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

   <View
    android:id="@+id/relChart"
    android:layout_above="@+id/input_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

   <RelativeLayout
    android:id="@+id/relChart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/background"
   >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_centerVertical="true"
        android:layout_margin="5dp"
        android:layout_toLeftOf="@+id/ivSend"
        android:background="@drawable/border_round_white3"
        android:gravity="right|center_vertical"
        android:paddingRight="10dp"
        android:textColor="@android:color/black"
        android:textCursorDrawable="@null"
        android:maxLength="140"
        />

    <ImageView
        android:id="@+id/ivSend"
        android:layout_width="40dp"
        android:layout_height="35dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:contentDescription="@null"
        android:padding="5dp"
        android:src="@mipmap/send_icon" />
</RelativeLayout>
    </RelativeLayout>

Upvotes: 0

Ravi
Ravi

Reputation: 35549

remove android:layout_alignParentBottom="true" from both your EditText and ImageView will solve your proble.

Your RelativeLayout already have android:layout_alignParentBottom="true" and if you will set same for it's child also it will set layout height to full screen.

Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM

Class Document

Upvotes: 11

Related Questions