如何填充父相对布局中的所有空间? [英] How to fill all space in parent Relative layout?
本文介绍了如何填充父相对布局中的所有空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个小例子来说明我的问题.在示例中,我创建了一个RelativeLayout来填充整个屏幕.还有3个孩子:
I created a small example to explain my problem. In the example I created a RelativeLayout that fills the whole screen. And 3 children :
- id为中间的FrameLayout必须填充所有空白空间,且不会在FrameLayout的顶部和底部(粉红色)上覆盖
- id为top的FrameLayout必须显示在中间(红色)上方
- 底端ID必须在中间(黄色)下方显示的FrameLayout
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/top"
android:layout_width="100dp"
android:layout_height="24dp"
android:layout_above="@id/middle"
android:background="#FFFF0000" />
<FrameLayout
android:id="@+id/middle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF00FF" />
<FrameLayout
android:id="@+id/bottom"
android:layout_width="100dp"
android:layout_height="24dp"
android:layout_below="@id/middle"
android:background="#FFFFFF00" />
</RelativeLayout>
我的示例结果的屏幕截图:
还有屏幕截图,我需要做什么:
推荐答案
好的,这段代码应该可以做到.
Okay, this code should do it.
签出:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/top"
android:layout_width="100dp"
android:layout_height="24dp"
android:background="#FFFF0000"
android:layout_alignParentTop="true" />
<FrameLayout
android:id="@+id/bottom"
android:layout_width="100dp"
android:layout_height="24dp"
android:background="#FFFFFF00"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="@+id/middle"
android:layout_above="@id/bottom"
android:layout_below="@id/top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFF00FF" />
</RelativeLayout>
这篇关于如何填充父相对布局中的所有空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文