Android中在屏幕上涂鸦的例子
来源:互联网 发布:h3c 把端口加入vlan 编辑:程序博客网 时间:2024/05/19 19:43
这个例子,自定义了一个View,可以接受touch动作,然后在屏幕上即时的显示出touch的轨迹,类似于线条的涂鸦。这个例子主要是演示如何将onTouchEvent与draw配合起来使用。在这个基础上,可以做很多有用的程序。
import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Paint.Style; import android.view.MotionEvent; import android.view.View; /** * Example for hand writing. * * @author http://blog.csdn.net/arui319 * @version 2010/09/07 * */ public class HandwritingView extends View { private Paint paint = null; private Path path = null; public HandwritingView(Context context) { super(context); path = new Path(); paint = new Paint(); paint.setColor(Color.YELLOW); paint.setStyle(Style.STROKE); paint.setAntiAlias(true); this.setBackgroundColor(Color.BLACK); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); path.moveTo(x, y); invalidate(); return true; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { int x = (int) event.getX(); int y = (int) event.getY(); path.lineTo(x, y); invalidate(); return true; } return super.onTouchEvent(event); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (path != null) { canvas.drawPath(path, paint); } } }
0 0
- Android中在屏幕上涂鸦的例子
- Android中在屏幕上涂鸦的例子
- Android中在屏幕上涂鸦的例子
- Android中在屏幕上涂鸦的例子
- Android屏幕上涂鸦画笔标记的实现
- android 实现在照片上涂鸦
- android:在照片上绘制涂鸦
- Android在ImageView上做一些涂鸦
- C# 在屏幕上画图效果的经典例子
- android涂鸦程序(在图像上绘制)
- android 在图片上涂鸦(添加水印同理)
- pjsip在android上使用的例子
- 一个简单的涂鸦例子
- Android: 解决GridView、ListView在ScrollView中出现冲突的问题 ——诺诺"涂鸦"记忆
- Android中Listview的getChildAt()只能更新当前显示在屏幕上的Item的解决办法
- Android中Listview的getChildAt()只能更新当前显示在屏幕上的Item的解决办法
- DrawingView android上的一个自定义涂鸦控件
- Android涂鸦的实现
- 上传文件,并获取文件名
- android计时器类CountDownTime的运用及扩展
- redis 命令操作笔记
- java面试整理(一)
- Android获取其他包的Context实例,然后调用它的方法
- Android中在屏幕上涂鸦的例子
- System.getProperties的key与value.
- Android颜色选择器
- 简单的jdbc封装+servlet的封装
- 数据结构- 快速排序
- Android中使用Bezier曲线
- C3P0配置文件解析
- WPF 去边框 自定义窗体 拖动窗体大小变化
- Eclipse 打开鼠标悬停提示功能