相对布局对齐右下角的图像

Sai*_*ira 3 android android-layout android-relativelayout

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

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

Cri*_*ian 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>
Run Code Online (Sandbox Code Playgroud)

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