TextView文字旋转

Android TextView文字旋转45°效果图如图:

图片资源:    


RotateTextView:

[java]  view plain  copy
  1. import android.content.Context;  
  2. import android.graphics.Canvas;  
  3. import android.util.AttributeSet;  
  4. import android.widget.TextView;  
  5.   
  6. /** 
  7.  *  
  8.  * @author Tyler 
  9.  * @time 2015-11-25 下午1:45:07 
  10.  */  
  11. public class RotateTextView extends TextView{  
  12.   
  13.       
  14.     public RotateTextView(Context context) {  
  15.         super(context);  
  16.     }  
  17.       
  18.     public RotateTextView(Context context, AttributeSet attrs) {  
  19.         super(context, attrs);  
  20.     }  
  21.   
  22.     @Override  
  23.     protected void onDraw(Canvas canvas) {  
  24.         //倾斜度45,上下左右居中  
  25.         canvas.rotate(45, getMeasuredWidth()/2, getMeasuredHeight()/2);  
  26.         super.onDraw(canvas);  
  27.     }  
  28.       
  29. }  


XML:

[html]  view plain  copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="match_parent"  
  3.     android:layout_height="match_parent"  
  4.     android:orientation="vertical"  
  5.     android:background="@color/white" >  
  6.   
  7.     <包名.RotateTextView  
  8.         android:layout_width="54dip"  
  9.         android:layout_height="54dip"  
  10.         android:layout_alignParentRight="true"  
  11.         android:background="@drawable/e_rotate_bg2"  
  12.         android:gravity="center"  
  13.         android:paddingBottom="17dp"  
  14.         android:text="进行中"  
  15.         android:textColor="#fff"  
  16.         android:textSize="12sp" />  
  17.   
  18. </RelativeLayout>  
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值