标题、内容和没有alignParentBottom=“true”的RelativeLayout中的页脚

发布于 2024-12-20 12:07:49 字数 1366 浏览 4 评论 0原文

我有以下设置来获得带有页眉和页脚的布局。由于活动显示在对话框中,我想将顶部元素的高度设置为“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.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心奴独伤 2024-12-27 12:07:49

使用垂直 LinearLayout 代替:

<?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="vertical" >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HEAD"/>
    <!--LinearLayout containing the list here, to go with your posted code, 
it would also work to just have the list outside the layout.-->
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">
        <ListView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FOOT"/>
</LinearLayout>

这样,主体将随着其内容而增长,直到没有更多空间。然后它将开始下降到页脚后面(尽管这应该不是问题,因为您使用 ListView 来显示内容,因此视图将扩展到最大尺寸,然后停止,并且滚动将开始工作)。

Use a vertical LinearLayout instead:

<?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="vertical" >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HEAD"/>
    <!--LinearLayout containing the list here, to go with your posted code, 
it would also work to just have the list outside the layout.-->
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">
        <ListView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FOOT"/>
</LinearLayout>

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).

还在原地等你 2024-12-27 12:07:49

既然您说这是一个对话框窗口,从某种意义上说,如果您愿意,您可以无限期地延长对话框的高度。您可以简单地在底部元素上使用 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 set LNL_CONTENT's height to match_parent, then it will fill in whatever space is between.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文