对齐右下角的图像 [英] Aligning images about right bottom corner

查看:81
本文介绍了对齐右下角的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用相对布局将一个较小的图像叠加在一个较大的图像之上. 我希望较小图像的右下角与较大图像的B-R角重合.我在布局XML中使用了边距参数(以倾角指定尺寸),但这似乎不适用于所有设备和分辨率-在某些情况下,小图像会从边框移开4-5px.

I am using relative layout to superimpose one smaller image on top of a larger one. I want the bottom-right corner of the smaller image to coincide with B-R corner of the larger image. I'm using margin parameters in my layout XML (specifying measurement in dips) but this doesn't seem to work for all devices and resolutions - in some cases the small image is shifted by 4-5px from the border.

是否可以指定没有像素值的较小图像的位置? IE.引力之类的东西?

Is it possible to specify the position of the smaller image without pixel values? I.e. with gravity or something?

推荐答案

<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*参数,以确保两个图像对齐.请记住,我为小图像设置了特定的尺寸,但是您可以根据自己的需要进行更改.

Nice thing about RelativeLayout is that you can use relative positions and dimensions, instead of using specific dips or pixels. In the case above, I just played with the android:layout_align* parameters, to make sure that both images are aligned. Keep in mind that I set a specific dimension of the little image, but you can change that to fit your needs.

这篇关于对齐右下角的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆