Skip to content

Instantly share code, notes, and snippets.

@BrunoVT1992
Last active April 26, 2016 07:38
Show Gist options
  • Save BrunoVT1992/3d522bafac9542271e339fc8351ca6a5 to your computer and use it in GitHub Desktop.
Save BrunoVT1992/3d522bafac9542271e339fc8351ca6a5 to your computer and use it in GitHub Desktop.
Rotated textview for Xamarin Android
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