在自定义的圆里中间写入文字
来源:互联网 发布:源mac地址全是0的报文 编辑:程序博客网 时间:2024/05/17 06:16
package com.example.kirito.animation360_1.view;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.util.Log;import android.view.View;/** * Created by kirito on 2016.11.24. */public class FloatCircleView extends View { public int width = 150; public int height = 150; private Paint circlePaint; private Paint textPaint; private static final String TAG = "FloatCircleView"; //三个构造函数都必须调用,否则无法正常使用自定义view public FloatCircleView(Context context) { this(context,null); } public FloatCircleView(Context context, AttributeSet attrs) { this(context, attrs,0); } public FloatCircleView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initPaint(); } public void initPaint(){ circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); textPaint = new Paint(); textPaint.setAntiAlias(true); textPaint.setTextSize(25); textPaint.setColor(Color.RED); textPaint.setFakeBoldText(true); } @Override protected void onDraw(Canvas canvas) { canvas.drawCircle(width / 2,width / 2,width / 2,circlePaint); String text = "50%"; float textWidth = textPaint.measureText(text); float x = (width - textWidth) / 2; Paint.FontMetrics metrics = textPaint.getFontMetrics(); //ascent是负的,descent是正的,dy是正的 float dy = -(metrics.ascent + metrics.descent) / 2; float y = height / 2 + dy; canvas.drawText(text,x,y,textPaint); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(width,height); }}
0 0
- 在自定义的圆里中间写入文字
- Android自定义控件之——文字圆形边框(将文字绘制在圆中间)
- Android自定义控件之——文字圆形边框(将文字绘制在圆中间)
- 自定义view文字在矩形里居中
- Swift里自定义一个文字在左、图片在右的,标题按钮
- 在Activity画面中间添加闪烁的文字,
- 将文字画在给定的文本框正中间
- word2003 当在一行文字中间插入文字时,后面的文字为何会自动删除?
- 在文字里爬行,
- textview 中初始化之后,textView的光标在中间,初始化文字也是在textView中间的问题
- 实现自定义Toast里的文字跟图片
- 如何在navigationBar的中间添加一张自定义图片?
- 自定义gallery,避免选中项总在中间的问题
- 自定义gallery,避免选中项总在中间的问题
- Android 自定义带数字的圆形进度条和中间是文字的圆形进度条View
- 关于文字在div中间显示
- 在cmd 里写入MySQL
- 光标变粗,在文档的中间输入文字后面的文字就被覆盖转自我的新浪博客
- MySQL日期时间函数大全
- Slow performance occurs when you copy data to a TCP server by using a Windows Sockets API program
- 第十三周项目3-Dijkstra算法的验证
- git分支管理
- 16.11.25
- 在自定义的圆里中间写入文字
- Linux kernel mmc 框架说明,包括mmc_test使用方法
- Android Volley完全解析(四),带你从源码的角度理解Volley
- call to undefined function openssl_get_privatekey() 解決辦法
- java并发编程---sleep和wait
- sharepoint iframe
- FastDFS的配置、部署与API使用解读(1)Get Started with FastDFS
- C#设计模式- 观察者模式(2)
- 【noip 2004】 合并果子