标题、内容和没有alignParentBottom=“true”的RelativeLayout中的页脚
我有以下设置来获得带有页眉和页脚的布局。由于活动显示在对话框中,我想将顶部元素的高度设置为“wrap_content”。关于android文档,只要将alignParentBottm =“true”设置为子元素,这是不可能的。
在另一个问题中,有人建议使用 LinearLayout 并以编程方式设置 maxHeight。还有其他方法可以避免alignParentBottom =“true”吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LNL_TOP"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_alignParentTop="true">
</LinearLayout>
<LinearLayout
android:id="@+id/LNL_BOTTOM"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_alignParentBottom="true">
</LinearLayout>
<LinearLayout
android:id="@+id/LNL_CONTENT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/LNL_TOP"
android:layout_above="@+id/LNL_BOTTOM">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
这是当前外观的图像,我希望布局能够包裹内容并避免列表下方出现空白区域。
I have the following setup to get a layout with header and footer. Since the activity is displayed in a dialog, i want to set the height of the top element to "wrap_content". Regarding to the android docs this not possible as long as you set alignParentBottm="true" to a child element.
In an other question someone proposed to use a LinearLayout and set the maxHeight programmatically. Are there any other ways to avoid alignParentBottom="true" ?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LNL_TOP"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_alignParentTop="true">
</LinearLayout>
<LinearLayout
android:id="@+id/LNL_BOTTOM"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_alignParentBottom="true">
</LinearLayout>
<LinearLayout
android:id="@+id/LNL_CONTENT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/LNL_TOP"
android:layout_above="@+id/LNL_BOTTOM">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
Here is an image of what it currently looks like, I want the layout to wrap the content and avoid the empty space under the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用垂直 LinearLayout 代替:
这样,主体将随着其内容而增长,直到没有更多空间。然后它将开始下降到页脚后面(尽管这应该不是问题,因为您使用 ListView 来显示内容,因此视图将扩展到最大尺寸,然后停止,并且滚动将开始工作)。
Use a vertical LinearLayout instead:
With this, the body will grow with its content until there is no more space. Then it will start to go down behind the footer (although this shouldn't be a problem as you use a ListView for the contents, so the view will expand to maximum size and then stop, and the scrolling will start to work).
既然您说这是一个对话框窗口,从某种意义上说,如果您愿意,您可以无限期地延长对话框的高度。您可以简单地在底部元素上使用
layout_marginTop
将其推到您想要的最低位置,而不是与视图的底部对齐。如果将LNL_CONTENT
的高度设置为match_parent
,那么它将填充之间的任何空间。Since you said this is a dialog window, you could, in a sense, extend the height of the dialog indefinitely if you wanted. Instead of aligning to the bottom of the View, maybe simply use
layout_marginTop
on the bottom element to shove it to as low as you want. If you setLNL_CONTENT
's height tomatch_parent
, then it will fill in whatever space is between.