Search code examples
androidimageview

Put a button over an ImageView


I'm newbie in Android.

I would like to know if it's possible to put a button or another component over an ImageView. I've tried setting the image as a background image of a LinearLayout, but when I change between landscape and portrait mode, the image porportions are changed.

Thanks a lot.


Solution

  • Don't put the image as a background, you don't have any control on how the image is scaled. Instead, create a RelativeLayout, and put an ImageView as one of the child, and you can place anything (buttons etc) as other RelativeLayout children.

    <RelativeLayout ...>
        <ImageView (your image) ...>
        <Button (the button you want) ... />
    </RelativeLayout>