Last active
April 26, 2016 07:38
-
-
Save BrunoVT1992/3d522bafac9542271e339fc8351ca6a5 to your computer and use it in GitHub Desktop.
Rotated textview for Xamarin Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.Content; | |
using Android.Widget; | |
using Android.Util; | |
using Android.Graphics; | |
namespace Droid | |
{ | |
public class RotatedTextView : TextView | |
{ | |
public RotatedTextView(Context ctx, IAttributeSet attr) | |
: base(ctx, attr) | |
{ | |
} | |
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) | |
{ | |
base.OnMeasure(heightMeasureSpec, widthMeasureSpec); | |
SetMeasuredDimension(MeasuredHeight, MeasuredWidth); | |
} | |
protected override bool SetFrame(int left, int top, int right, int bottom) | |
{ | |
return base.SetFrame(left, top, left + (bottom - top), top + (right - left)); | |
} | |
protected override void OnDraw(Canvas canvas) | |
{ | |
canvas.Translate(0, Width); | |
canvas.Rotate(-90); | |
canvas.ClipRect(0, 0, Width, Height, Region.Op.Replace); | |
base.OnDraw(canvas); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment