public class RotateTextView extends TextView {
private float mRotateDegrees = -48.0f;
private float x = 35f / 1.5f;//将px转换成dip 为了方便适配 这个是在480*800的下面做的 如果不是 请将1.5f改成自己所要的值 1.5f就是480*800 默认的密度值
private float y = 13f / 1.5f;
public RotateTextView (Context context) {
super(context);
x = x * context.getResources().getDisplayMetrics().density;//动态的x,y
y = y * context.getResources().getDisplayMetrics().density;
}
public RotateTextView (Context context,AttributeSet paramAttributeSet){
super(context, paramAttributeSet);
x = x * context.getResources().getDisplayMetrics().density;
y = y * context.getResources().getDisplayMetrics().density;
}
@Override
protected void onDraw(Canvas canvas) {
// canvas.rotate(mRotateDegrees);
canvas.rotate(mRotateDegrees, x, y);
super.onDraw(canvas);
}
}
如图:
Android TextView 倾斜角度
最新推荐文章于 2021-05-26 21:32:30 发布