创建具有2个调整大小视图的Android布局
在我的布局中,我需要一个页眉、一个列表视图和一个带有创建具有2个调整大小视图的Android布局,android,android-layout,Android,Android Layout,在我的布局中,我需要一个页眉、一个列表视图和一个带有TextView的页脚。TextView需要调整大小,最多5行。想想facebook聊天吧,在那里你有一个蓝色的标题,上面有你朋友的名字,中间的内容窗格,下面有一个文本框,当你输入内容时,这个文本框会变大: [header] a fragment that takes up about 50dp [content] [content] [content] [content] something like a ViewGroup w
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\u width
和layout\u height
值为空,因为我不知道将它们设置为什么
更新
起初,我认为问题是因为我的
EditText
设置为maxLines=5
和TextMultiline
,但我尝试删除了所有内容,但只删除了一个硬编码高度的按钮,插入内容仍然覆盖了所有内容。我还尝试设置
,但是内容
刚刚介绍了页脚
来创建这样的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>
对于页脚:
footer.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
****
****
检查这个……我希望它有帮助。目前,我已经在Values文件夹中为ListView定义了一个array.xml,其中包含一些空条目。你必须用代码来处理它
<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>
问题在于所包含的页脚
布局是另一个相对布局
。footer
布局包含设置layout\u alignParentBottom=“true”
的元素,这使得页脚布局占据整个屏幕。我不知道它为什么会这样做,但事情就是这样。Hi.看看我的答案是否对你有帮助你至少试过我的布局文件了吗?我真的怀疑它是否像你在问题中所说的那样。对不起,但是你当前的答案掩盖了页脚
@ceaser:尝试在相对布局中设置android:layout\u marginBottom=“50dip”
。。请参阅我编辑的答案,其中显示了标题
,内容
,以及底部的50 DP间隙。页脚仍然不在那里。我的假设是footer
也向上移动了50dp
,而内容刚好覆盖了它。试试android:layout\u marginBottom=“-50dip”
也不起作用。它只是让content
超出了屏幕底部,所以列表中的最后几项不会出现。
<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>