1

我得到了一个框架的三个图像,左、中和右。左右是我作为包装内容提供的普通图像。中间的一个是可以水平扩展的修补图像。我需要使用相对布局来对齐它们。但中心图像不能有固定大小(因为它水平扩展)。我可以通过以下代码使用线性布局来做到这一点:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/cD"
        android:src="@drawable/l_left_corner" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/l_vertical_streatch"
        android:contentDescription="@string/cD" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/cD"
        android:src="@drawable/l_right_corner" />
</LinearLayout>

谁能告诉我如何在相对布局中做同样的事情(如果可能的话,也可以在框架布局中)?

编辑:我的完整布局(带有嵌套权重)

http://pastie.org/8469454#1-2

4

1 回答 1

1

您可以使用以下代码,当您使用一些真实图像时,只需将 40dp 从我的左右 ImageViews 切换到 wrap_content。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageView
    android:id="@+id/image_left"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentLeft="true"
    android:background="#FF0000"
    />

<ImageView
    android:id="@+id/image_center"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_centerHorizontal="true"
    android:layout_toRightOf="@id/image_left"
    android:layout_toLeftOf="@id/image_right"
    android:background="#00FF00"
    />


<ImageView
    android:id="@+id/image_right"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentRight="true"
    android:background="#0000FF"
    />
</RelativeLayout>

这是结果:相对布局

于 2013-11-10T10:21:41.357 回答