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 im开发者_Go百科age 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 is deprecated, so it's probably best to use relative layout alongside with 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.
You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight()
and getIntrinsicWidth()
and then set Image's scaleType
to FIT_XY
(this saves image's ratio, and also makes its size correct, while FIT_CENTER
does not).
精彩评论