SlantedTextView icon indicating copy to clipboard operation
SlantedTextView copied to clipboard

Just a few lines to accomplish your results and more

Open Youbang opened this issue 8 years ago • 4 comments

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;

Youbang avatar Jul 05 '16 03:07 Youbang

Here's a screenshot of my results:

abcd

Youbang avatar Jul 05 '16 04:07 Youbang

A very good way ! Wish you could creat a repository on Github. :)

HeZaiJin avatar Jul 05 '16 06:07 HeZaiJin

The variables should be written in camelCase e.g. roundRadius instead of RoundRadius

janheinrichmerker avatar Jul 05 '16 08:07 janheinrichmerker

Hehe, please ignore the coding style and just look at the method I proposed :)

Youbang avatar Jul 05 '16 13:07 Youbang