在 ImageView 上放置一个按钮
我是 Android 新手。
我想知道是否可以在 ImageView 上放置一个按钮或其他组件。我尝试将图像设置为 LinearLayout 的背景图像,但是当我在横向和纵向模式之间更改时,图像比例会发生变化。
多谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不要将图像作为背景,您无法控制图像的缩放方式。相反,创建一个RelativeLayout,并将ImageView 作为子级之一,并且您可以将任何内容(按钮等)作为其他RelativeLayout 子级。
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.
试试这个代码...它对你有帮助....
试试这个代码.....
在按钮中给出参数来设置按钮位置......
并且还给出图像路径......
Try this code... it's Help you....
Try this Code .....
In that give paramater in button to set your Button Position....
And also give Path of Image....
还有另一种方法,http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/
谢谢。
There is another way to do it,http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/
Thank you.
最简单的方法是使用
FrameLayout
。The simpliest way to do it is to use a
FrameLayout
.使用
ConstraintLayout
可以轻松实现这一点。Button
的约束设置为ImageView
。Button
拖动到ImageView
上您想要的任何位置以对其进行定位。This is easy using the
ConstraintLayout
.Button
to theImageView
.Button
anywhere you want over theImageView
to position it.对于那些使用约束布局的人:只需使用 ImageView 并将其所有四个边的约束添加到 Parent,然后也添加其他视图。
For those using Constraint Layout: Just use an ImageView and add its constraints from all the four side to Parent and than add the other views as well.