在ImageView上放一个按钮

gut*_*ory 19 android imageview

我是Android的新手.

我想知道是否可以在ImageView上放置一个按钮或其他组件.我已经尝试将图像设置为LinearLayout的背景图像,但是当我在横向和纵向模式之间切换时,图像部分会被更改.

非常感谢.

Ran*_*ku' 41

不要将图像作为背景,您无法控制图像的缩放方式.相反,创建一个RelativeLayout,并将ImageView作为子项之一,您可以将任何(按钮等)放置为其他RelativeLayout子项.

<RelativeLayout ...>
    <ImageView (your image) ...>
    <Button (the button you want) ... />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

  • 看起来资源中的顺序很重要,在Button之后放置ImageView对我来说不起作用,但是上面的顺序确实如此. (3认同)