简体   繁体   中英

Positioning images to fit all size screens

I'm having a problem with positioning images,I need to position a lot images over another larger background image.

An image Like this 在此处输入图片说明

I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog, but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.

I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.

any ideas would help me big time thanks

AbsoluteLayout已弃用,因此最好将相对布局与dp一起使用。

You could use relative layout so you can use layout_below="@id/view1" , android:layout_toRightOf="@id/view2" , and android:layout_toLeftOf="@id/view3" . You can also use android:layout_marginLeft="10dip" , android:layout_marginRight="10dip" , android:layout_marginTop="10dip" , and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.

您可以使用其可绘制对象的getIntrinsicHeight()getIntrinsicWidth()手动计算图像的可见宽度和高度,然后将Image的scaleType设置为FIT_XY (这样可以保存图像的比例,并且使其尺寸正确,而FIT_CENTER则不然)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM