zoukankan      html  css  js  c++  java
  • Android 自定义倾斜字体

    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;
        }
    }
    
    <com.h3c.classboard.teacher.RotateTextView
        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" />
    

      

  • 相关阅读:
    multiprocessing总结
    CPython在CPU密集型应用下的并发
    多线程交互
    线程等待与守护线程
    Python多线程(1)
    一个简单的单线程异步服务器
    多线程与多进程的实现
    socket的功能分割到不同函数
    数据处理项目Postmortem
    M2 终审
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/10382917.html
Copyright © 2011-2022 走看看