我正在使用相对布局将一张小图像叠加在一张大图像上方。我希望小图像的右下角与大图像的B-R角重合。我在我的布局XML中使用了margin参数(以dips为单位指定测量值),但这似乎并不适用于所有设备和分辨率 - 在某些情况下,小图像会从边框偏移4-5个像素。
有没有可能在不使用像素值的情况下指定小图像的位置?例如通过重力或其他方式?
有没有可能在不使用像素值的情况下指定小图像的位置?例如通过重力或其他方式?
<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*
参数即可确保两个图像对齐。请记住,我设置了小图像的特定尺寸,但您可以根据需要更改它。