На платформе Android есть возможность повернуть View на указанный градус. В этой статье рассматривается пример, в котором реализован указанный поворот.
Создайте собственный View под названием RotatedTextView. Вам необходимо унаследовать его от TextView (или любого другого View) и переопределить 3 конструктора:
package com.seostella.rotatesample;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextView;
public class RotatedTextView extends TextView {
public RotatedTextView(Context context) {
super(context);
}
public RotatedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public RotatedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(5, 0, 0);
super.onDraw(canvas);
canvas.restore();
}
}
Для поворота используется переопределенный метод onDraw(). Поворот происходит с помощью функции canvas.rotate(). В данном случае View повернется на 5 градусов.
Чтобы добавить RotatedTextView в xml-разметку воспользуйтесь следующим кодом:
<com.seostella.rotatesample.RotatedTextView
android:layout_height="40dip"
android:layout_width="fill_parent"
android:text="Rotate Canvas Sample" />
В итоге Вы увидите на экране эмулятора (мобильного телефона) следующее окно: