2

我有一个布局,其中红色块位于黑色区域的中心,蓝色矩形需要位于白色和红色块之间。有人知道如何制作这种布局的框架吗?

在此处输入图像描述

4

2 回答 2

1

您必须使用与视图相关的一些属性来实现您的目标,您必须执行以下操作:

在此处输入图像描述

将提到的属性应用于您的视图,您将获得结果。

有关更多信息,请参阅以下链接

相对布局

于 2013-01-09T10:59:17.403 回答
1

其他答案都没有真正回答问题,问题清楚地表明,红色框位于中心,蓝色框位于红色上方。

为了实现这一点,您需要将相对布局中的参数与 BlueBox 的参数混合,这是一个使用 TextViews 的示例:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/textView2"
    android:layout_below="@id/textView1"
    android:layout_centerHorizontal="true"
    android:gravity="center_vertical"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

textView2 在 textView1 和 parentTop 之上,因此它将占据所有空间。然后你使用它自己的内部重力使 Vertical 居中,使其内容居中。

于 2013-01-09T11:14:57.977 回答