[英]How to Rotate textview without canvas
我想以180度顯示textview。如何顯示這樣的textview 我已經嘗試通過擴展textview.But我不能設置長度和高度,我不知道為什么。
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;
}
}
如何不擴展TextView並使用setRotation(float),setRotationX(float)(和y)。 另外,必要時也不要忘記設置樞軸點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.