简体   繁体   中英

Draw bubble programmatically with arrow

I am implementing the following Class from Stackoverflow

https://stackoverflow.com/a/20811323/1936925

but I need a bubble like this

在此处输入图片说明

I am trying a lot, but don't know how to do it.

What edits do I need to do in order to get the above drawable.

Try this:

public Bitmap overlay(Bitmap image, String content) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        //My bg bitmap, use yours
        Bitmap background = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(MapActivity.context.getResources(), R.drawable.marker_base, options), marker_width, marker_height, true);
        //your red bitmap here
        Bitmap bmOverlay = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        canvas.drawBitmap(background, new Matrix(), paint);
        canvas.drawBitmap(image, 3, 3, paint);

        if (content != null)
        {
            //Use your TextSize and Color and paddings
            paint = new Paint();
            paint.setColor(Color.BLACK);
            if (content.length() < 11)
                paint.setTextSize(13);
            else
                paint.setTextSize(10);
            //30 / 28, 17 - my paddings
            canvas.drawText(content, (content.length() < 11)?30:28, 17, paint);
        }
        return bmOverlay;
    }

Solved

mPointer.rLineTo(80, 0);
mPointer.rLineTo(0, 60);
mPointer.rLineTo(-(80), -60);
mPointer.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM