![](https://i-blog.csdnimg.cn/blog_migrate/b52b968f5cb3e107645c2c040e1a2b96.png)
这是需求
需要自定义控件继承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); } }
布局文件
![](https://i-blog.csdnimg.cn/blog_migrate/364e0e668d5cf630a7cf93855af049d3.png)
亲测有效具体布局适当调节