我想以 180 度显示 textview。如何显示这样的 textview我已经通过扩展 textview 尝试过。但我无法设置长度和高度,我不知道为什么。
public class MyTextView180 extends TextView {
private int angle = 180;
public MyTextView180(Context context, AttributeSet attrs) {
super(context, attrs);
this.setGravity(Gravity.CENTER);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
}
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
canvas.rotate(angle, this.getWidth() / 2f, this.getHeight() / 2f);
super.onDraw(canvas);
canvas.restore();
}
public void setAngle(int textAngle) {
angle = textAngle;
}
}