如何使浮动像屏幕上的图像泡沫看法? [英] How make image view to float like bubble on screen?

查看:168
本文介绍了如何使浮动像屏幕上的图像泡沫看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个Android应用程序中,我想有,它漂浮在屏幕上时,一些动作发生气泡。可能有人请帮助我在这里。我打破我的头过去四天,但我不能补回来。所以,请帮助我在这里。先谢谢了。

I am trying to make an android application in which i would like to have bubbles which float on the screen when some action takes place. Could some one please help me here. I am breaking my head for the past four days but i could not make it up. So please help me here. Thanks in advance.

推荐答案

,这将是更好地使用的画布处理绘制自己。

Instead of using ImageViews, for your use case, it would be better to use a Canvas to handle the drawing yourself.

画具有透明背景的全屏的画布。创建位图数组(您想画画,记得用一个圆圈面膜,使他们的泡沫状的每个图像之一,注意内存问题),并吸引他们在不同的位置来筛选。

Draw a canvas fullscreen with a transparent background. Create an array of bitmaps(one for each image you want to draw, remember to use a circle mask to make them bubble shaped, watch out for memory issues) and draw them to screen at different positions.

使用自定义的RNG算法来生成位图的适当位置,然后绘制它们在画布上。使用主题来处理动画。

Use a custom RNG algorithm to generate appropriate positions for your bitmaps, and then draw them on the canvas. Use a Thread to handle the animations.

这里的在code产生一个圆形裁剪位图:

Here's the code for generating a circular cropped bitmap:

int targetWidth = 100;
    int targetHeight = 100;
    Bitmap targetBitmap = Bitmap.createBitmap(
        targetWidth,
        targetHeight,
        Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(
        ((float)targetWidth - 1) / 2,
        ((float)targetHeight - 1) / 2,
        (Math.min(((float)targetWidth), ((float)targetHeight)) / 2),
        Path.Direction.CCW);
    canvas.clipPath(path);
    Bitmap sourceBitmap = BitmapFactory.decodeResource(
        getResources(),
        R.drawable.my_image);
    canvas.drawBitmap(
        sourceBitmap,
        new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
        new Rect(0, 0, targetWidth, targetHeight),
        null);
    ImageView imageView = (ImageView)findViewById(R.id.my_image_view);
    imageView.setImageBitmap(targetBitmap);

当然,你将不得不修改此code绘制位图到画布上,而不是在ImageView的设置它的。这将是更有效,一次裁剪位图,然后裁剪后的图像放到位图的数组。

Of course, you will have to modify this code to draw the bitmap to the canvas instead of setting it in the ImageView. It would be more efficient, to crop the Bitmap once, then place the cropped image into the array of Bitmaps.

这篇关于如何使浮动像屏幕上的图像泡沫看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆