package org.touch.cn;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.app.ListActivity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class MyPaintView extends View{
private List<Point> allpoint = new ArrayList<Point>();//保存所以的操作坐标
public MyPaintView(Context context, AttributeSet attrs) {//接收context,同时接收属性集合。
super(context, attrs);//调用父类的构造
super.setOnTouchListener(new OnTouchListenerimpl());
}
private class OnTouchListenerimpl implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
Point p = new Point((int)event.getX(),(int)event.getY());//将坐标保存在Point类
if(event.getAction()==MotionEvent.ACTION_DOWN){ //用户按下
MyPaintView.this.allpoint=new ArrayList<Point>();//重绘
MyPaintView.this.allpoint.add(p);//保存坐标点
}else if(event.getAction()==MotionEvent.ACTION_MOVE){//用户移动
MyPaintView.this.allpoint.add(p);//记录坐标点
MyPaintView.this.postInvalidate();//重绘图形
}else if(event.getAction()==MotionEvent.ACTION_UP){//用户松开
MyPaintView.this.allpoint.add(p);//记录坐标点
MyPaintView.this.postInvalidate();//重绘图形
}
return true; //表示下面的操作不在执行了。
}
}
@Override
protected void onDraw(Canvas canvas) { //进行绘图
Paint paint = new Paint();//依靠此类开始画线
paint.setColor(Color.RED);
if(MyPaintView.this.allpoint.size()>0)//有坐标点保存的时候开始进行绘图
{
Iterator<Point> iterator = MyPaintView.this.allpoint.iterator();
Point first=null;
Point last=null;
while(iterator.hasNext()){
if(first==null)
{
first= (Point)iterator.next();//取出坐标
}else {
if(last!=null){//前一阶段已经完成
first = last;//重新开始下一阶段
}
last=(Point)iterator.next();//结果点坐标
canvas.drawLine(first.x, first.y, last.x, last.y, paint);
}
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
TouchDemo.zip (25个子文件)
TouchDemo
bin
classes.dex 4KB
TouchDemo.apk 14KB
resources.ap_ 10KB
org
touch
cn
MainActivity.class 505B
R$layout.class 376B
R$id.class 366B
R$drawable.class 382B
MyPaintView.class 2KB
R$attr.class 322B
MyPaintView$OnTouchListenerimpl.class 2KB
R.class 489B
R$string.class 409B
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
values
strings.xml 175B
drawable-mdpi
icon.png 3KB
layout
main.xml 388B
assets
default.properties 362B
gen
org
touch
cn
R.java 729B
proguard.cfg 1KB
src
org
touch
cn
MyPaintView.java 2KB
MainActivity.java 292B
.project 845B
.classpath 280B
AndroidManifest.xml 678B
共 25 条
- 1
A一剑飞鸿
- 粉丝: 847
- 资源: 52
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 学生成绩管理系统-C++版本
- 吉林大学离散数学2笔记.pdf
- 通道处理过程的模拟通常涉及对通道处理机制的理解与实现.txt
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页