Android中在屏幕上涂鸦的例子
来源:互联网 发布:侠客风云传 知乎 编辑:程序博客网 时间:2024/05/28 05:13
这个例子,自定义了一个View,可以接受touch动作,然后在屏幕上即时的显示出touch的轨迹,类似于线条的涂鸦。这个例子主要是演示如何将onTouchEvent与draw配合起来使用。在这个基础上,可以做很多有用的程序。
(注意invalidate()这个方法。这个比较关键。加入这个方法的调用主要是为了强制View进行重画。)
package com.arui; 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); } } }
来源:http://blog.csdn.net/arui319/article/details/5870651
- 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涂鸦的实现
- [C#] 網頁Html轉PDF檔(一行程式碼解決)
- 判断是否是IP
- erlang——ETS和DETS表学习笔记
- ecmall数据库表解析
- 完全复制沪深300指数
- Android中在屏幕上涂鸦的例子
- C++之异常处理
- 有关软件开发中的一些想法
- 从那一天起,你就成了我的全部
- 关于DM9000在ARM总线上的地址
- C# .net 字符串格式化,正则表达式,字符串操作
- 新手学习Cognos BI 10
- 游戏开发公司源代码防泄密解决方案
- sqlserver数据库性能分析定位经典语句