效果如下:

代码:

<com.andye.OffcutView                android:layout_width="30dp"                android:layout_height="30dp"/>
public class OffcutView extends View {    private String Text ="";//    private int textSize = 22;    private int radius=6;    public ChampionShipOffcutView(Context context) {        super(context);    }    public ChampionShipOffcutView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public ChampionShipOffcutView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    @SuppressLint("DrawAllocation")    protected void onDraw(Canvas canvas) {        if(Text==null)        {            return;        }        int w = getWidth(), h = getHeight();        Paint paint = new Paint();        paint.setAntiAlias(true);        paint.setStyle(Paint.Style.FILL);        paint.setColor(Color.argb(255, 69, 112, 234));        canvas.drawCircle(radius, radius, radius, paint);        Path path = new Path();        path.moveTo(radius, 0);        path.lineTo( w, 0);        path.lineTo(0, h);        path.lineTo(0, radius);        path.close();        canvas.drawPath(path, paint);        canvas.save();        TextPaint textPaint = new TextPaint();        textPaint.setColor(Color.argb(255, 255, 255, 255));        textPaint.setAntiAlias(true);        textPaint.setTextSize(w/4);        float x,y;        y=w*0.707f;        y=(y*8)/10;        x=(float) (-textPaint.measureText(Text))/2;        canvas.rotate(-45);        canvas.drawText(Text, x , y, textPaint);        canvas.restore();    }    public void setText(String str) {        Text = str==null?"":str;        invalidate();    }    }

更多相关文章

  1. Android,visibility属性
  2. android 分段显示文本颜色控件
  3. android开机自启广播无效果的曲线解决方案
  4. 怎么让Linearlayout里面的textview垂直居中
  5. android字体小结
  6. [1] Android主要源代码组成
  7. Android(安卓)P窗口机制之Window加载流程
  8. android监听短信
  9. Android(安卓)Studio 活动的启动模式 standard singleTop single

随机推荐

  1. 我的Android进阶之旅------>Android疯狂
  2. android实现下拉列表 ListView
  3. android中文字体
  4. Android(安卓)TTS学习——独特你的名字
  5. Android 日志工具类
  6. Android如何分析和研究Monkey Log文件
  7. android ViewPager之OnPageChangeListene
  8. AndroidTimer使用(三)-补充篇
  9. Google code android开源项目(二)
  10. android 自定义toast停留时间