public class RotateTextView extends AppCompatTextView {

private static final int DEFAULT_DEGREES = 0;

private int mDegrees;

public RotateTextView(Context context) {

super(context, null);

}

public RotateTextView(Context context, AttributeSet attrs) {

super(context, attrs, android.R.attr.textViewStyle);

this.setGravity(Gravity.CENTER);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RotateTextView);

mDegrees = a.getDimensionPixelSize(R.styleable.RotateTextView_degree, DEFAULT_DEGREES);

a.recycle();

}

@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(-27,25);

canvas.rotate(mDegrees);

super.onDraw(canvas);

canvas.restore();

}

public void setDegrees(int degrees) {

mDegrees = degrees;

}

}

android:id="@+id/info"

android:layout_width="72dp"

android:layout_height="72dp"

android:gravity="center"

android:text="哈 哈"

android:textColor="@color/colorWhite"

android:textSize="@dimen/font14"

app:degree="-46dp" />

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐