Search code examples
androidandroid-layoutandroid-viewandroid-relativelayout

List is taking too much space and EditText with buttons can't be viewed


I want to have a ListView, followed by a EdiText, folowed by 2 buttons like:

ListView <NEWLINE>
EditText  <NEWLINE>
Button1 Button2 <NEWLINE>

I have the code and if the list is small everything goes well. However, if the list has many elements it will take all the space and I won't be able to see the EditText or the buttons.

I have trimmed it down to the part where the problem starts:

<?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">

    <ListView android:id="@+id/in"
    android:layout_below="@id/button_contacts"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll"
    android:layout_weight="1.0" 
    />
    <EditText
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:drawable/editbox_background"
        android:layout_below="@id/in" />

   <Button
        android:id="@+id/Convert"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/entry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="Convert" />
   <Button
    android:id="@+id/sendSMS"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@id/Convert"
        android:layout_alignTop="@id/Convert"
        android:text="Send" />


</RelativeLayout>

How can I solve this?


Solution

  • the below code works for me and i hope it will work for you too...

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  style="@style/MainLinearLayout">"
    
    <TableLayout    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" 
                    style="@style/MainTableLayoutStyle">
    
        <ListView android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:id="@android:id/list"
                  android:layout_weight="1"
                  android:cacheColorHint="@color/transparent" 
    
                  >
    
        </ListView>
    
        <TableRow>
           <EditText
                android:id="@+id/entry"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@android:drawable/editbox_background"
                android:layout_below="@id/in" />
    
        </TableRow>
    
        <TableRow >
    
        <Button  android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:id="@+id/button1"
                     android:text="button1"
                     android:layout_gravity="left"
                     android:layout_weight="1"
                     />
    
        <Button  android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:id="@+id/button1"
                     android:text="button2"
                     android:layout_gravity="right"
                     android:layout_weight="1"
                     />
    
    
        </TableRow>
    
    </TableLayout>
    
    </LinearLayout>