且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

填写两个图像叠加像搜索栏上的图像视图触摸事件

更新时间:2023-01-28 19:30:36

这里的东西我想出了用夹路径。我用下面的图像(codeR颜色)外面的背景是一个坚实的和前景有一个含有透明背景的只有蓝色的圆圈。第一背景图像被绘制到屏幕上,然后夹路径被设置,使得进度图像,前景之一,被吸入适当在它的上面。

Here's something I came up with using clip path. I'm using following images (coder colours) out of which background is a solid one and foreground one contains only blue circle on transparent background. First background image is drawn onto screen, then clip path is set so that progress image, foreground one, is drawn properly on top of it.

背景图片; http://i.imgur.com/Sf6kg.png
前景图像; http://i.imgur.com/Svtoh.png

Background image; http://i.imgur.com/Sf6kg.png
Foreground image; http://i.imgur.com/Svtoh.png

而code;

private class ProgressView extends View {

    private Bitmap bgBitmap;
    private Bitmap fgBitmap;
    private RectF fullRect = new RectF();
    private Path clipPath = new Path();

    public ProgressView(Context context) {
        super(context);
        bgBitmap = BitmapFactory.decodeResource(
                                   context.getResources(), R.drawable.bg);
        fgBitmap = BitmapFactory.decodeResource(
                                   context.getResources(), R.drawable.fg);
    }

    @Override
    public void onDraw(Canvas c) {
        fullRect.right = getWidth();
        fullRect.bottom = getHeight();

        c.drawBitmap(bgBitmap, null, fullRect, null);

        float angle = SystemClock.uptimeMillis() % 3600 / 10.0f;

        clipPath.reset();
        clipPath.setLastPoint(getWidth() / 2, getHeight() / 2);
        clipPath.lineTo(getWidth() / 2, getHeight());
        clipPath.arcTo(fullRect, -90, angle);
        clipPath.lineTo(getWidth() / 2, getHeight() / 2);
        c.clipPath(clipPath);

        c.drawBitmap(fgBitmap, null, fullRect, null);

        invalidate();
    }   
}

这应该不会太困难,用体面的替代我的临时的图像和更适当的方式更新的角度。

Should it not be too difficult to replace my temporary images with decent ones and update the angle in a more appropriate way.