如何创建一个帮助叠加就像你在一些Android应用程序和ICS看?就像、你在、创建一个、应用程序

2023-09-11 12:51:05 作者:相顾无言

我想创建帮助叠加就像你看到的,当ICS负荷首次或类似ES文件浏览器或顶点启动应用软件的用户(还有更多,但我不认为他们现在)。这只是一个视图坐在另一个的顶部的相对布局?我一直没能找到任何样品$ C $下做这样的事。任何人都知道如何做到这一点,或有什么想法?

I am wanting to create help overlays like the ones you see when ICS loads for the first time or in apps like ES File Explorer or Apex Launcher (there are more, but I can't think of them right now). Is this just a relative layout with one view sitting on top of the other? I haven't been able to find any sample code for doing such a thing. Anyone know how this is done or have any ideas?

推荐答案

让我们假设你通常会叫的setContentView(R.layout.main),但在第一次运行,你想拥有这样的覆盖。

Let's assume you ordinarily would call setContentView(R.layout.main), but on first run, you want to have this overlay.

步骤#1:用Java code创建一个的FrameLayout ,并传递给的setContentView()

Step #1: Create a FrameLayout in Java code and pass that to setContentView().

步骤#2:使用 LayoutInflater 膨胀 R.layout.main 的FrameLayout

Step #2: Use LayoutInflater to inflate R.layout.main into the FrameLayout.

第三步:使用 LayoutInflater 膨胀覆盖到的FrameLayout

Step #3: Use LayoutInflater to inflate the overlay into the FrameLayout.

第四步:当用户点击该按钮(或其他)驳回覆盖,通话 removeView()从的FrameLayout 。

Step #4: When the user taps the button (or whatever) to dismiss the overlay, call removeView() to remove the overlay from the FrameLayout.

由于叠加是一个后来孩子的的FrameLayout ,它将漂浮超过了 R.layout.main 。

Since the overlay is a later child of the FrameLayout, it will float over top of the contents of R.layout.main.