一个可交互的Android绘制曲线的demo:

 

Android曲线绘制demo_第1张图片

 

 

package com.ray.demo;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Paint.Style;import android.graphics.Path;import android.graphics.Point;import android.graphics.RectF;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;public class LineFunActivity extends Activity {        @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(new SampleView(this));    }        private class SampleView extends View{    public static final int RECT_SIZE = 8;    private Point mSelectedPoint = null;public static final int POINT_ARRAY_SIZE = 7;public static final int C_START = 0;public static final int C_END = 1;public static final int C_CONTROL_1 = 2;public static final int C_CONTROL_2 = 3;public static final int Q_START = 4;public static final int Q_END = 5;public static final int Q_CONTROL = 6;private Point[] mPoints = new Point[POINT_ARRAY_SIZE];public SampleView(Context context) {super(context);mPoints[C_START] = new Point(100,100);mPoints[C_END] = new Point(200,200);mPoints[C_CONTROL_1] = new Point (150,100);mPoints[C_CONTROL_2] = new Point(150,200);mPoints[Q_START] = new Point(100,300);mPoints[Q_END] = new Point(150,400);mPoints[Q_CONTROL] = new Point(200,350);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);canvas.drawColor(Color.WHITE);// set up paintPaint paint = new Paint(Paint.ANTI_ALIAS_FLAG);paint.setColor(Color.BLACK);// draw the cubic linePath path = new Path();path.moveTo(mPoints[C_START].x,mPoints[C_START].y);path.cubicTo(mPoints[C_CONTROL_1].x, mPoints[C_CONTROL_1].y, mPoints[C_CONTROL_2].x, mPoints[C_CONTROL_2].y, mPoints[C_END].x, mPoints[C_END].y);paint.setStrokeWidth(2);paint.setStyle(Style.STROKE);canvas.drawPath(path, paint);canvas.drawLine(mPoints[C_START].x,mPoints[C_START].y, mPoints[C_CONTROL_1].x, mPoints[C_CONTROL_1].y, paint);canvas.drawLine(mPoints[C_END].x, mPoints[C_END].y, mPoints[C_CONTROL_2].x, mPoints[C_CONTROL_2].y, paint);// draw the quad linepaint.setColor(Color.BLACK);paint.setStyle(Style.FILL);paint.setStrokeWidth(2);path.reset();path.moveTo(mPoints[Q_START].x, mPoints[Q_START].y);path.quadTo(mPoints[Q_CONTROL].x, mPoints[Q_CONTROL].y, mPoints[Q_END].x, mPoints[Q_END].y);canvas.drawPath(path, paint);canvas.drawLine(mPoints[Q_START].x, mPoints[Q_START].y, mPoints[Q_CONTROL].x, mPoints[Q_CONTROL].y, paint);canvas.drawLine(mPoints[Q_END].x, mPoints[Q_END].y, mPoints[Q_CONTROL].x, mPoints[Q_CONTROL].y, paint);// draw control pointspaint.setColor(Color.RED);paint.setStyle(Style.FILL);for (int i=0; i

更多相关文章

  1. mono for android 读取网络远程图片
  2. android 将图片转换成黑白图片
  3. Android 曲线绘制Demo
  4. Android 代码改变图片颜色android:tint="@color/main_color" and
  5. layout中设置图片自适应大小,并且设置最大宽高
  6. android高仿抖音、点餐界面、天气项目、自定义view指示、爬取美
  7. android 图片处理
  8. android 安卓 开发 图片库获得图片的绝对路径
  9. TableRow 背景问题以及修改对话框标题高度或者图片

随机推荐

  1. SQL实现LeetCode(176.第二高薪水)
  2. Mysql8.0递归查询的简单用法示例
  3. SQL之各种join小结详细讲解
  4. SQL实现LeetCode(175.联合两表)
  5. 线上MySQL的自增id用尽怎么办
  6. 浅谈mysql join底层原理
  7. Mysql提权的多种姿势汇总
  8. 一篇文章带你深入了解Mysql触发器
  9. MySQL子查询中order by不生效问题的解决
  10. MySQL中utf8mb4排序规则示例