关于右下角相对布局对齐图片右下角、布局、图片

2023-09-06 06:05:44 作者:天不在亮.

我使用相对布局到一个较大的顶部叠加的还要小的图像。我想较小的图像的右下角与大图的B-R的角落一致。使用余量参数在我的布局的xml(在骤降指定测量),但是这并不即时似乎所有设备和分辨率工作 - 在某些情况下,小图像被4-5px从边界移

是否有可能以指定较小的图像的位置,而不像素数值即重力或什么??

解决方案

 < RelativeLayout的    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android    机器人:layout_width =FILL_PARENT    机器人:layout_height =FILL_PARENT>    < ImageView的        机器人:ID =@ + ID / big_image        机器人:layout_width =FILL_PARENT        机器人:layout_height =FILL_PARENT        机器人:SRC =@绘制/ bigimage/>    < ImageView的        机器人:ID =@ + ID / little_image        机器人:layout_width =50dip        机器人:layout_height =50dip        机器人:layout_alignRight =@ ID / big_image        机器人:layout_alignBottom =@ ID / big_image        机器人:SRC =@绘制/ littleimage/>< / RelativeLayout的> 

关于 RelativeLayout的好处是,你可以使用,而不是使用特定骤降或像素的相对的位置和尺寸。在上述情况下,我只是使用了与的android:layout_align * 参数,以确保两个图像对齐。请记住,我设置的小图像的特定尺寸,但你可以改变,以适应您的需求。

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. Im using margin parameters in my layout xml (specifying measurement in dips) but this doesnt seem to work for all devices and resolutions - in some cases the small image is shifted by 4-5px from the border.

借助SmartArt图设置图片对齐 布局 样式

Is it possible to specify the position of the smaller image without pixel values?? Ie 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>

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.