0

I'm trying to mimic the behaviour of the HTC SMS application (tradional view), where all messages are shown, and an EditTextis shown below. As you can see in the screenshot, when scrolling upwards, the EditText scrolls away at the bottom.

enter image description here

I'm stuck with this, even after reading multiple posts (eg Android Layout with ListView and Buttons and this website: http://www.finalconcept.com.au/article/view/android-keeping-buttons-visible), it's not working as expected.

Thanks to the comments and EditText now showing under ListView, I've managed to have my ListView take all available space and start scrolling once completed. The EditText is showing at the bottom of the screen now - always. I'd like it to disappear at the bottom when I scroll up though - now it remains at the bottom

Current Code:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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="@android:id/android:list"
            android:layout_width="fill_parent" 
            android:layout_height="0dp"
            android:layout_weight="1"
            />

    <TableLayout 
        android:layout_weight="0" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">

        <TableRow>
            <EditText android:id="@+id/newmessagecontent"
                android:layout_height="150dp" 
                android:singleLine="false"
                android:gravity="top"
                android:layout_width="250dp"
                android:layout_alignParentTop="true"
                  />

            <Button android:layout_height="wrap_content" 
                android:id="@+id/sendmessage" 
                android:text="Send" 
                android:layout_width="wrap_content"
                />
        </TableRow>
    </TableLayout>                  

</LinearLayout>

enter image description here

Community
  • 1
  • 1
user410932
  • 2,915
  • 4
  • 22
  • 23

2 Answers2

0

A ListView automatically scrolls if all the items in it take up more space than the view provides. What happens if you remove the ScrollView?

kibibyte
  • 3,007
  • 5
  • 30
  • 40
  • I started off with a with in it the and the . When the ListView contains too many items, the EditText is shifted under the bottom of my page and is no longer visible. Seems it's not scrolling automatically. – user410932 Aug 15 '11 at 19:38
  • In your TableLayout, try explicitly stating `android:layout_weight="0"`, and in your ListView, `android:layout_weight="1"`, as you had before. Does that work? – kibibyte Aug 15 '11 at 19:47
  • GiantMarshmallow no - not working either. I notice that as soon as I add the ScrollView, the ListView is shrinked to a couple of lines (as in the screenshot). Works fine when the ScrollView is not there, but of course, then my EditText disappears at the bottom of the page. Seems that when putting ListView in ScrollView, it's height becomes limited... – user410932 Aug 15 '11 at 19:51
  • Really? I'm testing your XML right now, with some of the modifications I suggested. [Here's what I have](http://pastie.org/private/ctzx2pmnultfm1idygpqq). The Eclipse graphical editor preview for this suggests that this works. (Side-note: you don't need `android:layout_alignParentTop` or `android:layout_above`. These attributes apply *only* when you're using a RelativeLayout) – kibibyte Aug 15 '11 at 20:05
  • GiantMarshmallow yes, that works but as I've described in my Edit in the meantime, it's not 100% what I was trying to achieve. I'd like the to disappear at the bottom when I scroll up again. Now it remains visible at all times. – user410932 Aug 15 '11 at 20:16
  • I've never actually tried to do that before, but try giving this a shot. In the ListView, try `android:layout_height="wrap_content"`. – kibibyte Aug 15 '11 at 20:30
0

i think what you need to implement here is some sort of modification of the SeparatedListAdapter from Jeff Sharkey from this Article. In this article he not only manages to add two Adapters to a ListView but also explains how to have Headers to separate them if you want (you can remove that part of the code).

So what i mean, is your first Adapter will be the data with It's rows, and the second Adapter will be a dummy one with no data that just points to a View with your controls or whatever.

this way the ListView and what you want to add at the bottom are gonna be all scrollable.

Hope this helps.

Ale K.
  • 316
  • 6
  • 18