要在Android中显示旋转的TextView,可以使用以下步骤:
public class TriangleView extends View {
private Path mPath;
private Paint mPaint;
public TriangleView(Context context) {
super(context);
init();
}
public TriangleView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public TriangleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mPath = new Path();
mPaint = new Paint();
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
mPath.reset();
mPath.moveTo(0, 0);
mPath.lineTo(width, 0);
mPath.lineTo(width / 2, height);
mPath.close();
canvas.drawPath(mPath, mPaint);
}
}
TextView textView = findViewById(R.id.textView);
Animation animation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
animation.setRepeatCount(Animation.INFINITE);
textView.startAnimation(animation);
这样就可以在三角形中显示旋转的TextView了。