Skip to content

Just a few lines to accomplish your results and more #1

@Youbang

Description

@Youbang

extend from TextView and override the draw method:

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
public void draw(Canvas canvas) {
    RectF rect = new RectF(ShrinkX, ShrinkY, getMeasuredWidth() - ShrinkX, getMeasuredHeight() - ShrinkY);

    if (OffsetX != 0 || OffsetY != 0) {
            canvas.translate(OffsetX, OffsetY);
        }

        if (Rotation != 0) {
            canvas.rotate(Rotation, rect.centerX(), rect.centerY());
        }

    if (RoundRadius > 0) {
        Path path = new Path();
        path.addRoundRect(rect, RoundRadius, RoundRadius, Path.Direction.CCW);
        canvas.clipPath(path);
    }

    paint.setColor(BackColor);
    canvas.drawRect(rect, paint);

    super.draw(canvas);
}

And of course you need to define some variables:

public int      RoundRadius = 0;
public int    BackColor   = 0;
public float    Rotation        = 0f;
public int    OffsetX           = 0;
public int    OffsetY           = 0;
public int      ShrinkX         = 0;
public int      ShrinkY         = 0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions