-
28-09-2019 - |
题
我正在使用相对布局将一个较小图像叠加在较大图像的顶部。我希望较小图像的右下角与较大图像的BR角相吻合。我在布局XML中使用了边距参数(在DIPS中指定测量值),但这似乎对所有设备和分辨率都不起作用 - 在某些情况下,小图像从边境转移了4-5px。
是否可以在没有像素值的情况下指定较小图像的位置?即带重力或其他东西?
解决方案
<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*
参数,以确保两个图像都对齐。请记住,我设置了小图像的特定维度,但是您可以更改它以满足您的需求。
不隶属于 StackOverflow