我试图实现两个嵌套的相对布局占用相等的空间AND来填充整个屏幕宽度。所有父布局都在宽度上设置了填充父布局。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>
对于两个ImageButton
,尝试将layout_width
属性设置为fill_parent
,然后添加:
android:scaleType="fitXY"
要使用相等的空间获取它们,必须将layout_weight
设置为相等的数字。
使用这个layout_weight=1。在两个RelativeLayout 中
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>