【问题标题】:Aligning images about right bottom corner关于右下角对齐图像
【发布时间】:2010-11-02 15:47:04
【问题描述】:
我正在使用相对布局将一个较小的图像叠加在一个较大的图像之上。
我希望较小图像的右下角与较大图像的 B-R 角重合。我在布局 XML 中使用边距参数(指定倾角测量值),但这似乎不适用于所有设备和分辨率 - 在某些情况下,小图像会从边框移动 4-5px。
是否可以在没有像素值的情况下指定较小图像的位置? IE。有重力什么的?
【问题讨论】:
标签:
android
android-layout
android-relativelayout
【解决方案1】:
<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* 参数,以确保两个图像都对齐。请记住,我设置了小图像的特定尺寸,但您可以根据需要进行更改。