3

我正在使用相对布局将一个较小的图像叠加在一个较大的图像之上。我希望较小图像的右下角与较大图像的 BR 角重合。我在我的布局 XML 中使用边距参数(指定倾角测量值),但这似乎不适用于所有设备和分辨率 - 在某些情况下,小图像从边框移动了 4-5px。

是否可以在没有像素值的情况下指定较小图像的位置?即重力还是什么?

4

1 回答 1

6
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/big_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/bigimage"/>
    <ImageView
        android:id="@+id/little_image"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:layout_alignRight="@id/big_image"
        android:layout_alignBottom="@id/big_image"
        android:src="@drawable/littleimage"/>
</RelativeLayout>

好处RelativeLayout是您可以使用相对位置和尺寸,而不是使用特定的倾角或像素。在上面的例子中,我只是使用了android:layout_align*参数,以确保两个图像都对齐。请记住,我设置了小图像的特定尺寸,但您可以根据需要进行更改。

于 2010-11-02T15:56:11.047 回答