
这是需求
需要自定义控件继承textview,一下是代码
@SuppressLint("AppCompatCustomView") public class RotateTextView extends TextView { public RotateTextView(Context context) { super(context); } public RotateTextView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { //倾斜度45,上下左右居中 canvas.rotate(45, getMeasuredWidth()/2, getMeasuredHeight()/2); super.onDraw(canvas); } }
布局文件

亲测有效具体布局适当调节