将图片对齐到右下角

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


1
太棒了!正是我在寻找的。 - Saideira

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接