面试例题4:绘制5行文本,每一行的字体大小逐渐增加
2012-07-23 20:39
417 查看
题目来自:《android高薪之路—android程序员面试宝典》一书 ,只是为了个人学习方便
实现如图效果:
使用Canvas.drawText方法绘制5行文本,每一行的字体大小逐渐增加
实现如图效果:
使用Canvas.drawText方法绘制5行文本,每一行的字体大小逐渐增加
package com.app; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; public class DrawTextView extends View{ private Paint paint = null; int y = 0; public DrawTextView(Context context) { super(context); paint = new Paint(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); float textSizeArray[]=new float[]{15,18,21,24,27}; for(int i=0;i<textSizeArray.length;i++){ paint.setTextSize(textSizeArray[i]); paint.setColor(Color.BLUE); //获取文本的宽度可以用measureText方法 //public void drawText(String text, float x, float y, Paint paint) //Parameters // text:The text to be drawn // x :The x-coordinate of the origin of the text being drawn // y :The y-coordinate of the origin of the text being drawn // paint :The paint used for the text (e.g. color, size, style) canvas.drawText( "Android(宽度:" +paint .measureText("Android")+ ")", 0, 50+y , paint ); //每行文字距离5个像素 y+= paint.getTextSize()+5; } } }
相关文章推荐
- iOS使用NSMutableAttributedString 实现富文本(一行文本里面不同字体大小)
- SpannableStringBuilder为文本设置不同字体大小,颜色
- myeclipse2017基础 设置控制台输出文本的字体大小
- VC对话框界面如何调整静态文本字体和大小?(转载)
- 图形的绘制,如何使用自定义画笔(颜色,线宽,线形)。如何为程序中添加选项菜单和选项设置对话框,如何使用标准颜色对话框,如何使用字体对话框,在选项对话框中实现预览功能。实现选项对话框和窗口类中的数据交换。如何改变对话框和控件的背景色,如何改变控件的文本颜色,
- Libgdx设置文本字体大小
- ios开发之改变UIWebView文本字体的样式和大小
- VC对话框调整静态文本和编辑框等字体和大小
- 使用XIB设置UILabel的换行及设置每一行的字体大小
- mfc如何改变静态文本框字体大小及mfc按钮问题用CButtonST进行图形按钮处理
- js+html5实现canvas绘制镂空字体文本的方法
- 在textarea里面插入图片,修改字体大小和颜色(文本富编辑)
- HTML 文本的颜色 段落的颜色和字体大小以及字体类型
- UGUI文本字体颜色和大小等代码修改
- MFC操作——设置静态文本 大小 字体格式 颜色
- 动态设置编辑框的大小、 文本字体、颜色等
- Myeclipse 10设置文本字体大小
- \t\t在textarea里面插入图片,修改字体大小和颜色(文本富编辑)
- iOS UILabel根据文本宽度改变字体大小
- iOS 富文本~设置字体大小和颜色