如何在窗口的所有视图之上覆盖图像?
我试图在我的活动之上放置一个覆盖层。换句话说,我想在整个屏幕的顶部放置一个渐变,所有视图都在它后面。
我目前有一个 LinearLayout
,其中包含我的按钮和所有内容。我是否可以扩展 LinearLayout 并在 onDraw 方法上添加一些内容,或者有什么方法可以添加另一个覆盖所有内容的布局?
I am trying to place an overlay on top of my Activity. In other words, I would like to put a gradient on top of the whole screen with all views behind it.
I currently have a LinearLayout
with my buttons and everything in it. Do I extend the LinearLayout
and add something on the onDraw
method, or is there any way I can add another layout that overlays everything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以做两件事:
用RelativeLayout替换LinearLayout,这样你就可以轻松地将你想要的任何东西放在彼此的顶部
将 LinearLayout 包装在 FrameLayout 中。 FrameLayout 按照定义/添加的顺序绘制所有内容,因此您的渐变应该是最后添加的视图/布局。
像这样的东西:
You can do two things:
replace the LinearLayout with a RelativeLayout and so you can easily place anything you want on top of each other
wrap your LinearLayout in a FrameLayout. The FrameLayout draws everything in order of definition/adding so your gradient should be the last added view/layout.
Something like that: