欢迎来到天天文库
浏览记录
ID:12640764
大小:62.50 KB
页数:3页
时间:2018-07-18
《android cavas阴影的绘制》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Androidcavas阴影的绘制在AndroidView中,要绘制阴影可以利用Paint物件的setShadowLayer函数.Java代码:publicclasshelloWorldextendsActivity{@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(newdrawCanvas(this));}classdrawCanvasextendsView{publicdrawCanvas(Contextcon
2、text){super(context);}@OverrideprotectedvoidonDraw(Canvascanvas){super.onDraw(canvas);//建立Paint物件PaintvPaint=newPaint();PaintvPaint2=newPaint();//--------------------------------------------//设定颜色vPaint.setColor(0xFFFFFF00);//实心矩形canvas.drawRect(30,50,130,150,vPaint);//设定阴影(柔边,X轴位移,Y轴位移,阴
3、影颜色)vPaint.setShadowLayer(5,3,3,0xFFFF00FF);//实心矩形&其阴影canvas.drawRect(30,200,130,300,vPaint);//--------------------------------------------//设定颜色vPaint2.setColor(0xFFFFFF00);//空心vPaint2.setStyle(Style.STROKE);//空心矩形canvas.drawRect(200,50,300,150,vPaint2);//设定阴影(柔边,X轴位移,Y轴位移,阴影颜色) vPaint2.
4、setShadowLayer(5,3,3,0xFFFF00FF);//空心矩形&其阴影canvas.drawRect(200,200,300,300,vPaint2);}}}
此文档下载收益归作者所有