如何在窗口的所有视图之上覆盖图像?

发布于 2024-12-23 05:49:21 字数 179 浏览 4 评论 0原文

我试图在我的活动之上放置一个覆盖层。换句话说,我想在整个屏幕的顶部放置一个渐变,所有视图都在它后面。

我目前有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奈何桥上唱咆哮 2024-12-30 05:49:21

你可以做两件事:

  1. 用RelativeLayout替换LinearLayout,这样你就可以轻松地将你想要的任何东西放在彼此的顶部

  2. 将 LinearLayout 包装在 FrameLayout 中。 FrameLayout 按照定义/添加的顺序绘制所有内容,因此您的渐变应该是最后添加的视图/布局。

像这样的东西:

<FrameLayout>
    <LinearLayout>
        <Your stuff>
    </LinearLayout>
    <GradientView/>
</FrameLayout>

You can do two things:

  1. replace the LinearLayout with a RelativeLayout and so you can easily place anything you want on top of each other

  2. 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:

<FrameLayout>
    <LinearLayout>
        <Your stuff>
    </LinearLayout>
    <GradientView/>
</FrameLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文