Android的布局 - 以下ListView和EditText上布局、Android、EditText、ListView

2023-09-04 05:50:18 作者:安然

我试图模仿HTC手机短信应用程序(土产视图),其中显示所有的消息的行为,如下图所示的EditTextis。正如你可以在截图中看到,向上滚动时,在滚动的EditText离开底部。

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.

我坚持这一点,即使在读取多个职位(如 Android的布局与ListView和按钮与本网站:的http:// www.finalconcept.com.au/article/view/android-keeping-buttons-visible ),它不是按预期工作。

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.

由于意见和现在的EditText下的ListView 显示,我已经成功有我的ListView采取一切可用的空间,并开始滚动一次完成。该EditText上是显示在屏幕的底部,现在 - 永远。我想它在底部消失的时候我虽然向上滚动 - 现在它仍然在底部

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

目前的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>

推荐答案

我想你需要在这里实现一些杰夫·夏基从排序 SeparatedListAdapter 的修改这文章。在这篇文章中,他不仅设法增加两个适配器的ListView 也解释了如何有头将它们分开如果你想(你可以删除的code的那部分)。

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.

这样的的ListView ,并要在底部添加的会是所有可滚动的东西。

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

希望这有助于。