㈠ android中使用paint怎么画虚线
Paint paint = new Paint ( ) ;
paint.setColor ( Color.BLACK ) ;
//设置画直线格式
paint.setStyle ( Paint.Style.STROKE ) ;
//设置虚线效果
paint.setPathEffect ( new DashPathEffect ( new float [ ] { 3, 2 }, 0 ) ) ;
最后这句是设置虚线效果,里边的float数组的意思是:先画长度为3的实线,再间隔长度为2的空白,之后一直重复这个单元。这个数组的长度只要大于等于2就行,你可以设置多个数值,产生不同效果,最后这个0指的是与起始位置的偏移量。
㈡ android canvas的drawText方法 如何设置字体大小和格式。
Canvas相当于画布,字体的大小格式在Paint上设置才正确, Paint 相当于画笔。代码如下,没有具体参数:
Paint paint = new Paint();
paint.setTextSize(textSize);//设置字体大小
paint.setTypeface(typeface);//设置字体类型
canvas.drawText(text, x, y, paint);//使用画笔paint
@Override
public void onDraw (Canvas canvas) {
Rect targetRect = new Rect(50, 50, 1000, 200);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(3);
paint.setTextSize(80);
String testString = "测试:ijkJQKA:1234";
paint.setColor(Color.CYAN);
canvas.drawRect(targetRect, paint);
paint.setColor(Color.RED);
FontMetricsInt fontMetrics = paint.getFontMetricsInt();
(2)androidpaint粗细扩展阅读:
Screen Space - Camera
此模式类似Screen Space - Overlay,但区别是此模式将Canvas放置于某个Camera前固定距离。此Camera负责渲染所有UI元素,则摄像机参数(Camera Settings)直接影响UI表现。
比如Camera是透视模式(Perspective),则UI元素会基于Field of View的值而扭曲变形。同样的,若屏幕分辨率变更,或者视觉平截体(CameraFrustrum)改变,则Canvas自动调整自身尺寸作自适应。
㈢ android中怎么设置线条paint粗细百度看见你解决了。求指教!
Paint.setStrokeWidth(X); x可以设置为你想要的宽度,例如5或者6
㈣ android如何实现消除imageview周围的一圈细细的白边
在图片显示时,图片空间ImageView居中,并让四周超出所在的layout一定的长度,这样就可以将白边掩盖掉。
Imageview设置背景图片时,总会因为图片的大小与控件大小不一致的情况,通常的做法是制作png格式的图片,背景是透明的,如果是其他的如jpg、gif都会有背景,就会出现黑边、白边的问题,一般公司开发手机项目,都会有一个专门的美工,提前做好一套png格式的图标,程序引用就可以。
㈤ android怎么用paint实现图像的渐变出现
在android.graphics中提供了有关Gradient字样的类,例如LinearGradient线性渐变、 RadialGradient径向渐变和SweepGradient角度渐变三种,他们的基类为android.graphics.Shader。为了演 示图像渐变效果,下面给出一个简单的实例。
一、LinearGradient线性渐变
在android平台中提供了两种重载方式来实例化该类分别为,他们的不同之处为参数中第一种方法可以用颜色数组,和位置来实现更细腻的过渡效果, 比如颜 色采样int[] colors数组中存放20种颜色,则渐变将会逐一处理。而第二种方法参数仅为起初颜色color0和最终颜色color1。
LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile)
LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, Shader.TileMode tile)
使用实例如下:
Paint p=new Paint();
LinearGradient lg=new LinearGradient(0,0,100,100,Color.RED,Color.BLUE,Shader.TileMode.MIRROR); //参数一为渐变起初点坐标x位置,参数二为y轴位置,参数三和四分辨对应渐变终点,最后参数为平铺方式,这里设置为镜像
刚才已经讲到Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变,代码如下:
p.setShader(lg);
canvas.drawCicle(0,0,200,p); //参数3为画圆的半径,类型为float型。
二、RadialGradient镜像渐变
有了上面的基础,我们一起来了解下径向渐变。和上面参数唯一不同的是,径向渐变第三个参数是半径,其他的和线性渐变相同。
RadialGradient(float x, float y, float radius, int[] colors, float[] positions, Shader.TileMode tile)
RadialGradient(float x, float y, float radius, int color0, int color1, Shader.TileMode tile)
三、SweepGradient角度渐变
对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形,相对来说比上面更简单,前两个参数为中心点,然后通过载入的颜色来平均的渐变渲染。
SweepGradient(float cx, float cy, int[] colors, float[] positions) //对于最后一个参数SDK上的描述为May be NULL. The relative position of each corresponding color in the colors array, beginning with 0 and ending with 1.0. If the values are not monotonic, the drawing may proce unexpected results. If positions is NULL, then the colors are automatically spaced evenly.,所以建议使用下面的重载方法,本方法一般为NULL即可。
SweepGradient(float cx, float cy, int color0, int color1)
到此,希望大家对图像特效处理有了一定的认识,了解这些对打好Android游戏开发的基础很有好处。
转载
㈥ android绘制圆角矩形为什么圆角边粗了
用shapedrawable画一个圆角矩形作为按钮的background,但是圆角的地方总是有点粗,和直接用xml做出来的背景不一样
float[]
outerR = new float[] { 20f, 20f, 20f, 20f, 0, 0, 0, 0 };
Shape shape = new
RoundRectShape(outerR, null, null);
image.setBackgroundDrawable(new
CustomShapeDrawable(shape,0xffea0000));
class CustomShapeDrawable extends
ShapeDrawable {
int color ;
public CustomShapeDrawable(Shape s,int
color) {
super(s);
this.color =
color;
}
@Override
protected void onDraw(Shape shape, Canvas
canvas, Paint paint) {
paint.setStrokeJoin(Join.ROUND);
paint.setDither(true);
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setColor(0xffea0000);
paint.setStrokeWidth(4f);
shape.draw(canvas, paint);
}
}
把paint.setStrokeJoin这行去掉再试试
㈦ android画板中的paint
paint对象设置一下抗锯齿为true看看,方法是setAntialias()
用quadTo()这个方法没什么问题
㈧ android中paint如何设置背景图片
首先paint的作用类似于一个画笔,你可以设置这个画笔的粗细,颜色,轨迹的STYLE等等,paint是不能用来设置背景的。
canvas可以理解为一个画布,你绑定一个画笔来在这个画布上作画,你也可以设置这个画布的背景,android中canvas画图利用的是bitmap,具体你去看看sdk中的canvas。
㈨ Android下通过Canvas类和Paint类画一个表格的方法的问题
Paint和Canvas类:
Paint:画笔,使用之前首先要调整好画笔,然后就可以在画布上绘图了,这样就可以显示在手机屏幕上。
主要方法有:setColor()
设置画笔的颜色
setTextSize()
设置字体大小
setStyle()
设置画笔的风格,空心还是实心
setStrokWidth()
设置空心的边框宽度
setTextAlign()
设置文字的对齐方式
setTypeface()
设置字体,如粗细、倾斜
在设置画笔颜色的时候,使用到了Color类,这个类定义了一些颜色常量和颜色转换。如Color.RED、Color.GRENN等,还可以通过Color类的静态方法rgb(int,int,int)
来定一个颜色,这三个参数的的值范围是0~255。
Canvas:是一个画布,可以在上面画想要的任何东西,也可以设置画布的一些的属性,比如背景颜色,尺寸等。Canvas提供了一下一些方法:
方法:Canvas(),创建一个空的画布,可以使用setBitmap()方法来设置绘制的具体画布;
Canvas(Bitmap
bitmap),以bitmap对象创建一个画布,此时则将内容绘制在bitmap上,bitmap不得为null.
drawColor(),设置画布的背景颜色。
drawRect(left,top,right,bottom,paint);画矩形,前四个是float,后一个是Paint类型。
drawLine(startX,startY,stopX,stopY,paint),画线,前四个参数是float,后一个是Paint类型。
drawText(text,x,y,paint);在画布上画指定的文本,x,y两个参数是float,后一个是Paint类型。