Android TextView文字旋轉45°

Android TextView文字旋轉45°效果圖如圖:

圖片資源:    


RotateTextView:

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * 
 * @author Tyler
 * @time 2015-11-25 下午1:45:07
 */
public class RotateTextView extends TextView{

    
    public RotateTextView(Context context) {
        super(context);
    }
    
    public RotateTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //傾斜度45,上下左右居中
        canvas.rotate(45, getMeasuredWidth()/2, getMeasuredHeight()/2);
        super.onDraw(canvas);
    }
	
}


XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/white" >

    <包名.RotateTextView
        android:layout_width="54dip"
        android:layout_height="54dip"
        android:layout_alignParentRight="true"
        android:background="@drawable/e_rotate_bg2"
        android:gravity="center"
        android:paddingBottom="17dp"
        android:text="進行中"
        android:textColor="#fff"
        android:textSize="12sp" />

</RelativeLayout>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章