Android自定义View之随屏幕旋转的TextView

RotateTextView

在个别时候我们需要文字随屏幕旋转,那么该怎么实现呢?自定义TextView就可以.
接下来我们贴出RotateTextView的实现代码:
“` python
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.TextView;

public class RotateTextView extends TextView {
private static final int DEFAULT_DEGREES = 0;
private int mDegrees;
public RotateTextView(Context context, AttributeSet attrs) {
super(context,attrs);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.save();
    canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
    //设置绕中心旋转mDegrees度
    canvas.rotate(this.mDegrees, this.getWidth() / 2f, this.getHeight() / 2f);
    Log.i("degree>>>>>>>>>>>",this.mDegrees+"");
    super.onDraw(canvas);
    canvas.restore();
}

//设置旋转角度
public void setDegree(int degrees) {
this.mDegrees = degrees;
//设置刷新界面
this.volidate();
}

}

最新文章更新在微信公众号上,欢迎关注获取详情:
这里写图片描述

觉得有用请关注我的博客哦,本文原创,转载请注明出处.

你可能感兴趣的:(Android-自定义View,Android,自定义控件,旋转)