Mj1992
Mj1992

Reputation: 3504

Android RelativeLayout overlapping

I've a relative layout in android for a chat application.The problem is that the listview on my screen when grows the last elements are hidden behind the textbox and button which I've placed at the bottom.

enter image description here

I am using the following layout file.

<?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" >
<LinearLayout     
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView android:id="@+id/PreviousChatsButton"
      android:padding="5dip"
      android:text="@string/ViewPreviousChats"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center_horizontal"
      android:focusable="true"
      >
</TextView>

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

</LinearLayout>

<TextView android:id="@+id/NoChatsMsg"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/NoNewChatMsg"
          />
<Button
    android:id="@+id/SubmitButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="@string/Submit"
    android:onClick="SubmitButtonClick" />


<EditText
    android:id="@+id/Chatbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@id/SubmitButton"
    android:layout_alignBottom="@id/SubmitButton"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@id/SubmitButton"
    android:ems="10"
    android:inputType="text" >
</EditText>

</RelativeLayout>

Upvotes: 1

Views: 8201

Answers (3)

Dalmas
Dalmas

Reputation: 26547

Use android:layout_above to avoid this problem :

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

    <Button
        android:id="@+id/SubmitButton" ... />

    <LinearLayout     
         android:layout_above="@id/SubmitButton" ... >
         ...
    </LinearLayout>

Note that you have to declare your button before the LinearLayout for this to work.

Upvotes: 1

Padma Kumar
Padma Kumar

Reputation: 20031

//try this its working fine for me

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/PreviousChatsButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:gravity="center_horizontal"
        android:padding="5dip"
        android:text="ViewPreviousChats" >
    </TextView>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="0dp" 
        android:layout_weight="1"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/NoChatsMsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/NoNewChatMsg" />

        <Button
            android:id="@+id/SubmitButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:onClick="SubmitButtonClick"
            android:text="@string/Submit" />

        <EditText
            android:id="@+id/Chatbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@id/SubmitButton"
            android:layout_alignBottom="@id/SubmitButton"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@id/SubmitButton"
            android:ems="10"
            android:inputType="text" >
        </EditText>
    </LinearLayout>
</LinearLayout>

Upvotes: 2

tyczj
tyczj

Reputation: 73721

what you want to do is in the LinearLayout do android:layout_above="@+id/Chatbox" that will make sure it does not go below it

Upvotes: 4

Related Questions