package com.police.policedatasystem.main;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextView;

public class RotatedTextView extends TextView {
  
    private float rotationAngle=300; // 旋转角度
  
    public RotatedTextView(Context context) {
        super(context);  
    }  
  
    public RotatedTextView(Context context, AttributeSet attrs) {
        super(context, attrs);  
    }  
  
    public RotatedTextView(Context context, AttributeSet attrs, int defStyleAttr) {  
        super(context, attrs, defStyleAttr);  
    }  
  
    // 设置旋转角度  
    public void setRotationAngle(float angle) {  
        this.rotationAngle = angle;  
        invalidate(); // 重新绘制  
    }  
  
    @Override  
    protected void onDraw(Canvas canvas) {
        int width = getWidth();  
        int height = getHeight();  
        int centerX = width / 10;
        int centerY = height / 3;
  
        canvas.save(); // 保存当前画布状态  
        canvas.translate(centerX, centerY); // 将坐标原点移动到中心点  
        canvas.rotate(rotationAngle, centerX, centerY); // 旋转画布  
        super.onDraw(canvas); // 绘制原始的TextView  
        canvas.restore(); // 恢复画布状态  
    }  
}