首先编写MyView类

代码如下:

package com.example.myhello;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View; public class MyView extends View{ public MyView(Context context,AttributeSet attrs){
super(context,attrs);
}
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas.drawCircle(50, 50, 30, paint);
paint.setColor(Color.BLACK);
canvas.drawRect(80,20,160,80,paint);
Rect rect = new Rect();
rect.set(180,20,300,80); canvas.drawRect(rect, paint);
paint.setStyle(Style.STROKE);
paint.setColor(Color.RED);
paint.setTextSize(20);
canvas.drawText("hello", 10, 108, paint);
paint.setColor(Color.BLACK);
canvas.drawLine(10, 120, 300, 120, paint);
RectF oval = new RectF();
oval.set(10.0f,140.0f,108.0f,200.0f);
canvas.drawOval(oval, paint);
oval = new RectF();
oval.set(150.0f,140.0f,210.0f,200.0f);
canvas.drawArc(oval, 150.0f, 140.0f, true, paint);
}
}

 然后改写main.xml文件

代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.example.myhello.MyView
android:id="@+id/myview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

 

android之简单图形绘制的更多相关文章

  1. ArcGIS Engine简单图形绘制功能的实现(点、线、面)

    我们添加点.线.面来实现图形的编辑需要使用Geometry对象类. Point(点) 是一个0维的几何图形,具有X.Y坐标值,以及可选的属性,如高程值(Z值).度量值(M值).ID值等,可用于描述需要 ...

  2. EmguCV 简单图形绘制

    一.圆 public static void cvCircle( IntPtr img, System.Drawing.Point center, //Center of the circle int ...

  3. 学习笔记:HTML5 Canvas绘制简单图形

    HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...

  4. Java入门:绘制简单图形

    在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...

  5. Python turtle库绘制简单图形

    一.简介 Python中的turtle库是一个直观有趣的图形绘制函数库.turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形. 二.简单的图形列举 1.绘制4个不同 ...

  6. Android自定义控件:图形报表的实现(折线图、曲线图、动态曲线图)(View与SurfaceView分别实现图表控件)

    图形报表很常用,因为展示数据比较直观,常见的形式有很多,如:折线图.柱形图.饼图.雷达图.股票图.还有一些3D效果的图表等. Android中也有不少第三方图表库,但是很难兼容各种各样的需求. 如果第 ...

  7. 自定义控件之Canvas图形绘制基础练习-青春痘笑脸^_^

    对于自定义控件的意义不言而喻,所以对它的深入研究是很有必要的,前些年写过几篇关于UI效果的学习过程,但是中途比较懒一直就停滞了,而对于实际工作还是面试来说系统深入的了解自定义控件那是很有必要的,所以接 ...

  8. 动画学习之Music图形绘制

    今天来实现一个类似于网易云音乐类似的动态效果,在用网易云音乐听歌时会有一个类似这样的效果,如下: 而咱们这次要实现的效果如下: music图形的绘制: 在实现动画之前先来将静态的图形绘制出来, 如下: ...

  9. 动画学习之WIFI图形绘制

    Android原生动画概述: 对于APP开发中涉及到的一些动画基本上都可以用Android提供的各种原生动画类来实现,所以在学习自定义动画之前首先来对原生动画进行一个基本的了解,这里不详细对每一个原生 ...

随机推荐

  1. react-基础(2)

    表单相关 固定的几个属性和事件 value: <input>,<textarea>; checked: <input> typeof checkbox, radio ...

  2. HTTP基础05--http首部

    HTTP 报文首部 HTTP 请求报文 在请求中,HTTP 报文由方法.URI.HTTP 版本.HTTP 首部字段等部分构成. HTTP 响应报文 在响应中,HTTP 报文由 HTTP 版本.状态码( ...

  3. Swift3.0语言教程删除字符与处理字符编码

    Swift3.0语言教程删除字符与处理字符编码 Swift3.0语言教程删除字符 Swift3.0语言教程删除字符与处理字符编码,在字符串中,如果开发者有不需要使用的字符,就可以将这些字符删除.在NS ...

  4. iOS10 UI设计基础教程

    iOS10 UI设计基础教程 介绍:本教程针对iOS初级开发人员,基于iOS 10系统,使用Swift 3.0语言讲解如何进行UI设计.本教程内容涵盖UI基础构成.UI元素.自动布局.自适应UI.UI ...

  5. 6754 Keyboard of a Mobile Telephone

    /*实践再次说明ch=getchar()的速度非常慢*/ /*大水题,不解释*/ #include<stdio.h> #include<string.h> int main() ...

  6. Graphics 导出图片使用【这个主要是画图类图的使用,记录一下】

    /// <summary> /// 导出信令流程矢量图 /// </summary> /// <param name="signalFlowInfos" ...

  7. spring-boot项目在外部tomcat环境下部署

    http://m.blog.csdn.net/article/details?id=51009423

  8. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

  9. mapreduce.framework.name

    mapreduce.framework.name默认是local: <property><name>mapreduce.framework.name</name>& ...

  10. IE下margin:0 auto为什么不居中?

    http://blog.sina.com.cn/s/blog_68c6be330101k7kn.html 我们经常用DIV+CSS布局网页的时候,正常情况下需要将div居中显示时,使用Css样式:ma ...