Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Youbang opened this issue Jul 5, 2016 · 4 comments
Open

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

Youbang opened this issue Jul 5, 2016 · 4 comments

Comments

@Youbang
Copy link

Youbang commented Jul 5, 2016

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
Copy link
Author

Youbang commented Jul 5, 2016

Here's a screenshot of my results:

abcd

@HeZaiJin
Copy link
Owner

HeZaiJin commented Jul 5, 2016

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

@janheinrichmerker
Copy link

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

@Youbang
Copy link
Author

Youbang commented Jul 5, 2016

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

HeZaiJin pushed a commit that referenced this issue Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants