Android 创建三个等距(子)布局,其中第一个在顶部,第三个在底部

Android 创建三个等距(子)布局,其中第一个在顶部,第三个在底部,android,android-layout,space,Android,Android Layout,Space,我已经尝试了很长一段时间,并没有找到一个令人信服的解决方案,下面的布局问题。例如,如果我使用RelativeLayout作为容器,我可以将其用于(子)布局a android:layout_alignParentTop="true" 和(子)布局图C 但是,似乎不可能以两个空间高度相同的方式放置布局B。有人在.xml中看到了解决方案吗 当将元素堆叠在另一个元素之上时,这是一个简单的选择。子布局A和子布局C仅占用它们所需的空间,剩余空间随后分配给子布局B以及填充剩余空间所需的任何间距。这可以通过

我已经尝试了很长一段时间,并没有找到一个令人信服的解决方案,下面的布局问题。例如,如果我使用RelativeLayout作为容器,我可以将其用于(子)布局a

 android:layout_alignParentTop="true"
和(子)布局图C

但是,似乎不可能以两个空间高度相同的方式放置布局B。有人在.xml中看到了解决方案吗


当将元素堆叠在另一个元素之上时,这是一个简单的选择。子布局A和子布局C仅占用它们所需的空间,剩余空间随后分配给子布局B以及填充剩余空间所需的任何间距。这可以通过将子布局B包装在a中来实现:


您会注意到
sub\u layout\u a
sub\u layout\u b
FrameLayout
可以是任何布局-只需确保
layout\u height=“wrap\u content”
(或固定值)只占用所需的空间即可

剩余空间通过使用
layout\u height=“0dp”
layout\u weight=“1”
分配给中间的
FrameLayout
——将其拉伸以填充所有剩余空间的是
layout\u weight
。这允许我们使用
android:layout\u gravity=“center\u vertical”
将内部
sub\u layout\u b
居中于该空间内,在
sub\u layout\u b
两侧留出相等的空白空间,尝试一下(抱歉,我现在无法测试):


...
...
...

给出a&b布局id并为b&c使用(android:layout_down=“@+id/the_id”)。看看这是否有助于Hanks Fer,实际上这与ianhanniballake的原理相同,只是使用了两个相等权重的占位符,而不是一个垂直居中的占位符。这个解决方案也应该起作用。
android:layout_alignParentBottom="true"> 
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <FrameLayout
        android:id="@+id/sub_layout_a"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </FrameLayout>
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <FrameLayout
            android:id="@+id/sub_layout_b"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">
        </FrameLayout>
    </FrameLayout>
    <FrameLayout
        android:id="@+id/sub_layout_c"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </FrameLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Any_layout_type_you_want
        android:id="@+id/sub_layout_a"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        ...
    </Any_layout_type_you_want>

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

    <Any_layout_type_you_want
        android:id="@+id/sub_layout_b"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        ...
    </Any_layout_type_you_want>

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

    <Any_layout_type_you_want
        android:id="@+id/sub_layout_c"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        ...
    </Any_layout_type_you_want>

</LinearLayout>