在自定义view中需要绘制出画笔的图片,并且在当前按下的位置实时绘制, 我的步骤是:(1)获取资源文件的下的画笔bitmap :               Bitmap bitmapPaint = BitmapFactory.decodeResource(mContext.getResources(),              R.mipmap.paint);             (2)在ondraw中  Canvas.drawBitmap(bitmapPaint,move_x,move_y,  new              Paint(Paint.Paint.ANTI_ALIAS_FLAG));实时绘制运行后结果发现:画笔不在当前按下的位置  经过查看源码发现:              canvas.drawBitmap(Bitmap bitmap, float left, float top, Paint paint)中 bitmap --- 需要绘制bitmap对象left ---- bitmap左边距离当前自定义view 左边的 距离top ---- bitmap上边距离当前自定义view 上边的 距离paint ---- 绘制的画笔 我要将画笔显示在当前按下的位置点,所以将bitmap向上平移bitmap的高度:    最终使用:         canvas.drawBitmap(bitmapPaint,move_x,move_y-bitmapPaint.getHeight(),  new       Paint(Paint.ANTI_ALIAS_FLAG));   move_x  --- 当前手指按下的屏幕x坐标   move_y  --- 当前手指按下的屏幕y坐标

 

更多相关文章

  1. Android(安卓)编译过程分析(1)
  2. 玩转Scroller打造平滑滚动效果
  3. android 顶部横向滑动菜单效果
  4. Android(安卓)listView scroll 恢复滚动位置
  5. Android(安卓)OpenGLES绘制yuv420纹理
  6. android ImageView 图片宽度全屏,高度自适应的写法
  7. [Android]使用RecyclerView替代ListView(三)
  8. LocationManager的使用
  9. android百度地图

随机推荐

  1. Windows7搭建Apache本地服务器+PHP环境
  2. 如何为$ wpdb-> insert创建一个包含colum
  3. 为什么cron工作不是从浏览器工作,但从终端
  4. php连接mysql的三种方法
  5. 如何递归将特色图像应用于Wordpress中的
  6. 将Ajax div内容存储在PHP变量中
  7. json_encode在数组上返回null
  8. 如何在发送之前更改SOAP请求中的名称空间
  9. 如何测试返回的json结果?
  10. 【php】php开发的前期准备