【实训】旋转的文字控件
来源:互联网 发布:抽签软件在线 编辑:程序博客网 时间:2024/05/22 02:11
因为项目要求,所以需要一个可以旋转的文字控件。
事实上这个控件并不难写。
1.继承TextView
2.成员变量mDegrees表示角度
3.重写onDraw方法
4.旋转canvas即可
import android.content.Context;import android.graphics.Canvas;import android.util.AttributeSet;import android.view.Gravity;import android.widget.TextView;public class RotateTextView extends TextView { 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); mDegrees = DEFAULT_DEGREES; } @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(getCompoundPaddingLeft(), getExtendedPaddingTop()); canvas.rotate(mDegrees, this.getWidth() / 2f, this.getHeight() / 2f); super.onDraw(canvas); canvas.restore(); } public void setDegrees(int degrees) { mDegrees = degrees; }}
阅读全文
0 0
- 【实训】旋转的文字控件
- 旋转的文字
- FastReport控件中Memo文字旋转
- 文字旋转
- 旋转文字
- 文字旋转
- android 随旋转而旋转的控件
- js旋转的变色的文字
- Flex中label的文字旋转
- 显示旋转文字的Javascript代码
- 怎样使单元格内的文字旋转
- 在图片添加旋转的水印文字
- 自定义竖直旋转显示文字的TextView
- 如何高雅的旋转textview文字显示
- 可以旋转文字的验证码
- 自定义竖直旋转显示文字的TextView
- 自定义竖直旋转显示文字的TextView
- 文字旋转的几种方法
- pb全局变量在哪定义
- 关于SeekBar的thumb和progress不相接有间隔的问题处理
- Unity3d 序列帧播放
- HTML5的video标签
- 爬虫的去重策略
- 【实训】旋转的文字控件
- HDU 1754 I Hate It
- 图像缩放之双三次插值法
- CF419 div2B. Karen and Coffee
- docker入门
- Java模块笔试
- Spring中设计模式的学习
- 自定义view实现通用的柱形图表
- 使用caffemodel模型(由mnist训练)测试单张手写数字样本