0

在我的布局中,我需要一个页眉、一个列表视图和一个带有TextView. TextView需要将大小调整为最多 5 行。想想 facebook 聊天,你有一个带有朋友名字的蓝色标题,中间的内容窗格和下面的文本框,随着你输入内容而增长:

[header]     a fragment that takes up about 50dp
[content]
[content]
[content]
[content]    something like a ViewGroup with a ListView in it
[content]
[content]
[content]
[footer]     a ViewGroup that contains an EditText and Buttons

我尝试了各种不同的布局设置,但无法正确设置。要么页脚占据所有空间,要么内容覆盖页脚。

这是我到目前为止所拥有的:

<LinearLayout ...>

    <!-- Slot to put Header fragment in -->
    <FrameLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Here's where the content goes. This is supposed to be a ListView
         inserted as a fragment -->
    <FrameLayout
        android:id="@+id/content"
        ... />

    <include
        android:id="@+id/footer"
        ... />

</LinearLayout>

我将layout_widthandlayout_height值留空,因为我不知道将它们设置为什么。

更新 最初,我认为问题是因为 myEditText设置为maxLines=5and TextMultiline,但我尝试删除除一个具有硬编码高度的按钮之外的所有内容,并且插入仍然覆盖了所有内容。我也尝试过设置<footer below="content">,但后来content就被覆盖了footer

4

3 回答 3

1

问题是footer包含的布局是另一个RelativeLayout. footer布局包含 set的元素layout_alignParentBottom="true",这使得页脚布局占据了整个屏幕。我不知道它为什么会那样做,但这就是发生的事情。

于 2012-09-26T02:09:28.723 回答
0

检查这个...我希望它有帮助。目前,我在 Values 文件夹中定义了一个 array.xml,其中包含一些 ListView 的空条目。您将不得不使用代码来处理它。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="HEADER" />    

        <ListView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/chats"
            android:layout_weight="1">

        </ListView>


        <EditText 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:lines="5"
            android:inputType="textMultiLine"
            android:hint=" Please enter your Chat" />  

</LinearLayout>
于 2012-09-21T13:46:50.363 回答
0

要创建这样的 UI,请创建一个布局

header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

<TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="xyz"
            android:textSize="10dp" />
</LinearLayout>

对于页脚:

页脚.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

<EditText

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="xyz"
            android:textSize="10dp" />
</LinearLayout>

如您所说,创建另一个包含 listView 的布局:main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
 **<include layout="@layout/header.xml" android:layout_alignParentTop="true"/>**   
<ListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        >
    </ListView>
 **<include layout="@layout/footer.xml" android:layout_below="@+id/listview" android:layout_alignParentBottom="true"/>**   
</RelativeLayout>
于 2012-09-20T10:40:17.510 回答