Saurabh
Saurabh

Reputation: 495

ListView hidden behind button

The contents of my list view get hidden behind the button as follows:

enter image description here

The xml file is:

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

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

<RelativeLayout
    android:id="@+id/InnerRelativeLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    > 

     <Button 
        android:text="Send" 
        android:id="@+id/Button"
        android:layout_alignParentRight="true" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="addItems"
       >
    </Button>

    <EditText 
        android:id="@+id/message" 
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@id/Button"
        android:layout_height="wrap_content"
        >
    </EditText>                
 </RelativeLayout>
 </RelativeLayout>

The TextView for each row is as follows:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content
    android:layout_gravity="right"
    android:gravity="right"
    android:textSize="20sp"
 />

What should i do to align it properly (as in above the button)? Also when the listView is with just one or two entries, and when the keyboard is opened to type, the whole view shifts? How do I fix that as well? Thanks in advance

Upvotes: 0

Views: 950

Answers (4)

sb_269
sb_269

Reputation: 563

Cleaned up and corected the code a bit. Perhaps this is what you were looking for. Let me know if it works. Cheers !

<?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"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/Button"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:onClick="addItems"
            android:text="Send" />

        <EditText
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:layout_toLeftOf="@id/Button" />
    </RelativeLayout>
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/InnerRelativeLayout" />
</RelativeLayout>

Upvotes: 2

M D
M D

Reputation: 47807

adding android:layout_above="@+id/InnerRelativeLayout" to your ListView.

RelativeLayout has child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on. By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.LayoutParams.

For put your InnerRelativeLayout layout at Top add android:layout_alignParentTop="true" to your InnerRelativeLayout and remove android:layout_alignParentBottom="true"

Update: set up your Layout like below:

<?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"
android:background="@color/Beige "
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/InnerRelativeLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" >

    <Button
        android:id="@+id/Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:onClick="addItems"
        android:text="Send" >
    </Button>

    <EditText
        android:id="@+id/message"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/Button"
        android:hint="Enter text" >
    </EditText>
</RelativeLayout>

<ListView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/InnerRelativeLayout"
    android:drawSelectorOnTop="false" />

</RelativeLayout>

Output:

enter image description here

Upvotes: 1

SDJMcHattie
SDJMcHattie

Reputation: 1699

Make the outer RelativeLayout into a LinearLayout with orientation vertical. Then, for the ListView set layout_height as 0dp and layout_weight as 1. The ListView will fill up all the remaining space in the LinearLayout without overlapping other views.

Also, stop using fill_parent, it's been deprecated and you should use match_parent instead.

Upvotes: 0

Kunu
Kunu

Reputation: 5134

use android:layout_above="@+id/InnerRelativeLayout" in your listview

Upvotes: 0

Related Questions