SlantedTextView
SlantedTextView copied to clipboard
Just a few lines to accomplish your results and more
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;
Here's a screenshot of my results:
A very good way ! Wish you could creat a repository on Github. :)
The variables should be written in camelCase e.g. roundRadius
instead of RoundRadius
Hehe, please ignore the coding style and just look at the method I proposed :)