布局问题:如何在顶部和底部放置东西?
我想创建一个布局,顶部和底部有一个水平的 LinearLayout,中间有一个 ListView 填充。
我如何定义main.xml。
我尝试创建一个布局,顶部为水平 LinearLayout,底部为 TextView,中间填充为 ListView;没问题。但是当我将底部TextView修改为LinearLayout后,底部LinearLayout消失了。
<?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"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<ListView
android:id="@+id/listbody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
有谁可以告诉一下建议吗? 请帮忙。
I want create a layout, with a horizontal LinearLayout(s) on top and bottom, a ListView fill in middle.
How can I define the main.xml.
I tried to create a layout with horizontal LinearLayout on top, TextView on bottom, a ListView fill in middle; is ok. But after I modified the bottom TextView to LinearLayout, the bottom LinearLayout disappear.
<?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"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<ListView
android:id="@+id/listbody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Anybody can tell advise?
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试将整个集合包含在相对布局中:
使用大小调整内容进行编辑。
Try containing the whole set in a RelativeLayout:
Edited with sizing stuff.
这就是您要找的东西。 Estel 使用RelativeLayout 走在正确的轨道上(虽然可以用LinearLayout 来完成,但我认为RelativeLayout 方法更干净)
但是布局乱了没关系,检查Estel 的评论证明了我错误的。 :) 你应该首先定义你的标题,将其与顶部对齐;接下来,定义页脚,并将其与底部对齐;最后,声明你的 ListView,给它一个 fill_parent 的高度,并将其设置为布局在页脚上方和标题下方:Here's what you're looking for. Estel's on the right track with the RelativeLayout (although it can be done with a LinearLayout, I think the RelativeLayout approach is cleaner, though)
but the layout is out of orderNevermind, check Estel's comment which proved me wrong. :) You should first define your header, align it to the top; next, define your footer, and align it to the bottom; finally, declare your ListView, give it a height of fill_parent, and set it to layout above the footer and below the header:问题是您正在相对于它们所包含的内容的大小来定义它们,但是如果两者的组合内容大于屏幕,那么其中一个将必须与另一个重叠,您最好在线性布局中使用绝对测量值定义layout_height
The problem would be that you are defining both of them relative to the size of the content they contain, but if the combined content of both is bigger than the screen then one of them will have to overlap the other one, you would be better to define the layout_height using an absolute measurement in a linear layout
感谢大家对RelativeLayout 的建议和指导。我现在可以修好它。
我必须在ListView之前定义页脚LinearLayout,并将ListView定义为 android:layout_alignParentTop="true" 和 android:layout_above="@id/footer"
Thanks all for your advice and direction of RelativeLayout. I can fix it now.
I have to define the footer LinearLayout before the ListView, and define ListView as android:layout_alignParentTop="true" and android:layout_above="@id/footer"
这肯定会解决你的问题:
This will definitely solve your problem: