androidstudio如何画图,关于Androidstudio基础画图用法

更新时间:2023-07-08 05:28:51 阅读: 评论:0

怀孕可以游泳吗androidstudio如何画图,关于Androidstudio基础画图⽤法
我们这篇帖⼦主要的还是给⼤家讲了⼀下怎么来⽤Path,这个在我们的android应⽤当中⽤到的很多,不多说什么了,在代码当中我已经注释了中⽂意思,⼤家还是来看看吧:
[b]java代码:[/b]
[code]
package eoe.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
t.Context;
aphics.Canvas;
aphics.Color;
aphics.Paint;
aphics.RectF;
aphics.Path;
aphics.Shader;
aphics.LinearGradient;
//主程序中继承⾃Android.view.View的 MyView类,重写 MyView的onDraw()⽅法,
//⼀开始就会运⾏绘制的⼯作,在onDraw()中以Paint将⼏何图形绘制在Canvas上,
//以 paint.tColor() 改变图形颜⾊、以 paint.tStyle()的设置来控制画出的的
//图形是空⼼还是实⼼。程序的最后⼀段,就是直接在Canvas写上⽂字,随着Paint对
//象⾥的属性设置,也会有不同的外观模式。
public class GraphicesActivity extends Activity {
/
** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
/*设置ContentView为⾃定义的MyVieW*/
MyView myView=new MyView(this);
西江月宋江tContentView(myView);
}
/* ⾃定义继承View 的MyView*/
private class MyView extends View {
public MyView(Context context){
super(context) ;
}
/*重写onDraw()*/
@Override
protected void onDraw(Canvas canvas) {
连wifi
/*设置背景为⽩⾊*/
canvas.drawColor(Color.WHITE);
Paint paint=new Paint();
/*去锯齿*/
paint.tAntiAlias(true);
/
*设置paint的颜⾊*/
paint.tColor(Color.RED);
/*设置paint的 style 为STROKE:空⼼*/
paint.tStyle(Paint.Style.STROKE);
/*设置paint的外框宽度*/
paint.tStrokeWidth(3);
/*画⼀个空⼼圆形*/
canvas.drawCircle(40, 40, 30, paint);
/*画⼀个空⼼正⽅形*/
canvas.drawRect(10, 90, 70, 150, paint);
/*画⼀个空⼼长⽅形*/
canvas.drawRect(10, 170, 70,200, paint);
/*画⼀个空⼼椭圆形*/
canvas.drawOval(new RectF(10,220,70,250), paint); /*画⼀个空⼼三⾓形*/
Path path=new Path();汪国真热爱生命
凉茶配方
path.lineTo(70,330);
path.lineTo(40,270);
path.clo();
canvas.drawPath(path, paint);
/*画⼀个空⼼梯形*/
Path path1=new Path();
网络瘫痪
path1.lineTo(70,410);
path1.lineTo(55,350);
path1.lineTo(25, 350);
path1.clo();
canvas.drawPath(path1, paint);
/*设置paint的颜⾊*/白居易的诗有哪些
paint.tColor(Color.BLUE);
/*设置paint 的style为 FILL:实⼼*/
paint.tStyle(Paint.Style.FILL);
/*画⼀个实⼼圆*/
canvas.drawCircle(120,40,30, paint);
/*画⼀个实⼼正⽅形*/
canvas.drawRect(90, 90, 150, 150, paint); /*画⼀个实⼼长⽅形*/
canvas.drawRect(90, 170, 150,200, paint); /*画⼀个实⼼椭圆*/
RectF re2=new RectF(90,220,150,250); canvas.drawOval(re2, paint);
/*画⼀个实⼼三⾓形*/
Path path2=new Path();
path2.lineTo(150,330);
path2.lineTo(120,270);
path2.clo();
canvas.drawPath(path2, paint);
/*画⼀个实⼼梯形*/
Path path3=new Path();
path3.lineTo(150,410);
path3.lineTo(135,350);
path3.lineTo(105, 350);
path3.clo();
canvas.drawPath(path3, paint);
/*设置渐变⾊*/
Shader mShader=new LinearGradient(0,0,100,100, new int[]{Color.RED,Color.GREEN,Color.BLUE,Color.YELLOW}, null,Shader.TileMode.REPEAT);
//Shader.TileMode三种模式
//REPEAT:沿着渐变⽅向循环重复
//CLAMP:如果在预先定义的范围外画的话,就重复边界的颜⾊
//MIRROR:与REPEAT⼀样都是循环重复,但这个会对称重复
paint.tShader(mShader);
//⽤Shader中定义定义的颜⾊来话
/*画⼀个渐变⾊圆*/
canvas.drawCircle(200,40,30, paint);
/*画⼀个渐变⾊正⽅形*/
canvas.drawRect(170, 90, 230, 150, paint);
/*画⼀个渐变⾊长⽅形*/
canvas.drawRect(170, 170, 230,200, paint);
/*画⼀个渐变⾊椭圆*/
RectF re3=new RectF(170,220,230,250);
canvas.drawOval(re3, paint);
/*画⼀个渐变⾊三⾓形*/
Path path4=new Path();
path4.lineTo(230,330);
path4.lineTo(200,270);
path4.clo();
canvas.drawPath(path4, paint);
/
*画⼀个渐变⾊梯形*/希望歌曲
Path path5=new Path();
path5.lineTo(230,410);
path5.lineTo(215,350);
path5.lineTo(185, 350);
path5.clo();
canvas.drawPath(path5, paint);
/*写字*/
paint.tTextSize(24);
canvas.drawText("圆形", 240, 50, paint); canvas.drawText("正⽅形", 240, 120, paint); canvas.drawTe
xt("长⽅形", 240, 190, paint); canvas.drawText("椭圆形", 240, 250, paint); canvas.drawText("三⾓形", 240, 320, paint); canvas.drawText("梯形", 240, 390, paint); }
}
}[/code]

本文发布于:2023-07-08 05:28:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1084923.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:设置   定义   渐变
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图