相对布局中视图重叠问题

4

期望的布局是一个标题,下面有两个框架(以后用来包含片段),并且按钮固定在屏幕底部:

     Header Text     
----------------------
frame 1   |  frame 2
----------------------
btn 1   btn 2   btn 3

我已经基本解决了这个问题(xml在末尾),只有一个问题... 两个框架重叠在按钮上。

我在这个问题上做了一些搜索,找到了这个,但它只是将我的问题从框架溢出按钮变成框架溢出标题栏。

我还尝试将按钮设置为出现在框架下方而不是与父元素底部对齐,但这只是把它们推出了屏幕。

当前的布局 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
            android:id="@+id/fdname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:clickable="true"
            android:gravity="center"
            android:text="No department info has been entered yet"
            android:textSize="25dp" />
    <TextView
            android:id="@+id/fdaddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/fdname"
            android:gravity="center"
            android:text="address"
            android:textSize="15dp" />
    <TextView
            android:id="@+id/horizontalline"
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:layout_below="@id/fdaddress"
            android:background="#ff23cf"
            android:gravity="center_vertical"
            android:paddingBottom="2dip"
            android:paddingTop="2dip" />
    <LinearLayout
            android:id="@+id/frames"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/horizontalline"
            android:orientation="horizontal" >
            <FrameLayout
                    android:id="@+id/leftpane"
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            <TextView
                    android:id="@+id/verticalline"
                    android:layout_width="2dp"
                    android:layout_height="match_parent"
                    android:background="#ff23cf"
                    android:gravity="center_horizontal"
                    android:paddingLeft="5dip"
                    android:paddingRight="5dip" />
            <FrameLayout
                    android:id="@+id/rightpane"
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:layout_weight="1" >
            </FrameLayout>
    </LinearLayout>
    <LinearLayout
            android:id="@+id/buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:orientation="horizontal" >
            <Button
                    android:id="@+id/EventViewButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:minHeight="25dp"
                    android:text="@string/menu_event_view"
                    android:textSize="15dp" 
                    android:layout_weight="1">
            </Button>
            <Button
                    android:id="@+id/MemberViewButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:minHeight="25dp"
                    android:text="@string/menu_member_view"
                    android:textSize="15dp" 
                    android:layout_weight="1">
            </Button>
            <Button
                    android:id="@+id/AttendanceViewButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:minHeight="25dp"
                    android:text="@string/menu_atnd_view"
                    android:textSize="15dp" 
                    android:layout_weight="1">
            </Button>
    </LinearLayout>
</RelativeLayout>

<LinearLayout android:id="@+id/frames" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/horizontalline" android:orientation="horizontal" > 为什么你的layout_height="match_parent"?这不应该是"wrap_content"吗? - CSmith
3个回答

6
尝试在包含按钮的 LinearLayout 之前声明一个 LinearLayout,并保留 android:layout_alignParentBottom="true" 属性。然后,在帧容器中添加一个 above 约束:
android:layout_below="@id/horizontalline"
android:layout_above="@id/buttons"

这种方法应该强制让你的框架成为屏幕上最后被绘制的东西,从而填充剩余的空间。
希望这能起作用!

听起来很不错,但我刚刚尝试了一下,仍然存在框架重叠按钮的问题。感谢您的努力。如果我找到解决方案,我会发布我的解决方法。 - Barak
2
好的,已经学到了。不要依赖图形布局来展示实际发生的情况。一旦我应用了代码,并实际在框架中显示了视图,它看起来和工作得像应该的样子(根据你在答案中建议的更改)。感谢你的帮助! - Barak

1
<LinearLayout             
    android:id="@+id/frames"             
    android:layout_width="match_parent"             
    android:layout_height="match_parent"             
    android:layout_below="@id/horizontalline"             
    android:orientation="horizontal" > 

为什么你的layout_height="match_parent"?你需要指定一些高度,或者使用wrap_content。

0

不理解...我不想要底部的框架,那么为什么要给它们添加alignbottom呢? - Barak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接