开发者

Making floating bubbles

I'm trying to make the background of my app have randomly floating bubbles. I've been looking around for anything similar, such as falling snowflakes, rain, etc. but I can't seem to find any examples.

Even if I can't make a bubble.png float randomly upwards, I'd like to at least have a . character or something that could represent "bubbles" like in a soda.

Any 开发者_如何学Pythonideas or references? Thanks!


You could place a SurfaceView behind your primary UI in a FrameLayout and draw the bubbles in the SurfaceView following one of the available tutorials. The rest of your UI would then overlay on top.

Example:

<FrameLayout android:layout_width="match_parent"
             android:layout_height="match_parent">
    <SurfaceView android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:id="@+id/surface" />
    <FrameLayout android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:id="@+id/app_content">
        <!-- Normal app UI goes here -->
    </FrameLayout>
</FrameLayout>

Warning: No matter what approach you take you're going to be redrawing the entire screen quite frequently several times per frame. (Animating the background plus drawing the UI.) Some ways will be faster than others but you are choosing to do more work than most apps do in drawing their UI. You will need to be mindful of performance and small inefficiencies; they will add up quickly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜