Android 中页眉在顶部、页脚在底部的布局
我正在尝试创建一个我认为非常简单的 Android 屏幕布局。我基本上想要顶部有一个页眉,底部有一个页脚,以及一个填充屏幕空间其余部分的 EditText 框。页眉和 EditText 框工作正常,但我似乎无法显示页脚。这是我的代码:
<?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="match_parent"
android:orientation="vertical">
<ImageView android:id="@+id/imageView1"
android:src="@drawable/droidiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</ImageView>
<View android:id="@+id/view1"
android:layout_height="2dip"
android:background="#FFAAAAFF"
android:layout_width="wrap_content">
</View>
<RelativeLayout android:id="@+id/rlLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:inputType="text|textMultiLine"
android:layout_alignParentTop="true"
android:hint="Type about your day..."
android:text=""
android:id="@+id/txtEntry"
android:layout_height="match_parent"
android:layout_width="match_parent">
</EditText>
<LinearLayout android:layout_alignParentBottom="true"
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View android:id="@+id/view2"
android:layout_height="2dip"
android:background="#FFAAAAFF"
android:layout_width="wrap_content">
</View>
<TextView android:text="TextView"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
就像我说的,除了我的页脚之外,一切正常。谁能告诉我我做错了什么?
I am trying to create an Android screen layout that I think is pretty simple. I basically want a header at the top and a footer at the bottom, along with an EditText box that fills the rest of the screen space. The header and EditText box is working fine, but I cannot seem to get my footer to display. Here is my code:
<?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="match_parent"
android:orientation="vertical">
<ImageView android:id="@+id/imageView1"
android:src="@drawable/droidiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</ImageView>
<View android:id="@+id/view1"
android:layout_height="2dip"
android:background="#FFAAAAFF"
android:layout_width="wrap_content">
</View>
<RelativeLayout android:id="@+id/rlLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:inputType="text|textMultiLine"
android:layout_alignParentTop="true"
android:hint="Type about your day..."
android:text=""
android:id="@+id/txtEntry"
android:layout_height="match_parent"
android:layout_width="match_parent">
</EditText>
<LinearLayout android:layout_alignParentBottom="true"
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View android:id="@+id/view2"
android:layout_height="2dip"
android:background="#FFAAAAFF"
android:layout_width="wrap_content">
</View>
<TextView android:text="TextView"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Like I said, everything works except my footer. Can anyone tell me what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的布局对于您想要实现的目标来说太复杂了。我建议避免
RelativeLayout
除非你绝对必须使用它。以下是如何使用
LinearLayout
创建页眉/内容/页脚布局的简单示例:(请注意
content
元素中的layout_weight
)Your layout is too complicated for what you want to achieve. I would recommend to avoid
RelativeLayout
unless you absolutely have to use it.Here is a simple example of how to create header/content/footer layout using
LinearLayout
:(note the
layout_weight
in thecontent
element)似乎有很多额外不需要的布局。这将为您布局三个区域,您可以在其中放置任何内容,或者只是将它们设为视图控件。每个区域的高度将为 25%、50%、25%。如果您不需要百分比,请删除页眉和页脚的权重并设置其宽度值,但保留 EditText 的权重。
There seems to be a lot of extra unneeded layouts. This will layout the three areas for you and you can put anything inside them or just make them a view control. The height of each area will be 25%, 50%, 25%. If you don't want percentages, remove the weights from the header and footer and set their width value but leave the weight of the EditText.
如果我正确理解布局的哪一部分是页眉和页脚,请添加以下行:
到 EditText
If I correctly understood which part of your layout is header and footer, add this line:
to EditText