0

我试图实现两个嵌套的相对布局占用相等的空间并填充屏幕的整个宽度。所有父布局都在宽度上设置了 fillparent。Eclipse 中的图形视图看起来不错,但我的 HTC 不同意——它将它们粘合在一起(我很好),但它也将它们移到了左边。我希望他们伸展。

  <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >

            <ImageButton
                android:id="@+id/button_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:src="@drawable/button_1_active" >
            </ImageButton>

            <TextView
                android:id="@+id/TextView01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/partners_info"
                android:textColor="@color/white"
                android:textStyle="bold" >
            </TextView>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/relativeLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             >

            <ImageButton
                android:id="@+id/button_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:src="@drawable/button_2_inactive" >
            </ImageButton>

            <TextView
                android:id="@+id/TextView02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/partners_map"
                android:textColor="@color/white"
                android:textStyle="bold" >
            </TextView>
        </RelativeLayout>
    </LinearLayout>
4

3 回答 3

1

对于这两个ImageButton尝试将layout_width属性设置为fill_parent,然后还添加:

    android:scaleType="fitXY"
于 2012-01-24T13:24:33.470 回答
0

使用这个 layout_weight=1。在两个RelativeLayout

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        >
于 2012-01-24T11:41:21.387 回答
0

要让它们使用相等的空间,您必须设置layout_weight为相等的数字。

于 2012-01-24T11:37:23.063 回答