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

 

 

 

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. Android(安卓)曲线绘制Demo
  2. Android(安卓)代码改变图片颜色android:tint="@color/main_color
  3. Android(安卓)OpenGL ES 开发教程小结
  4. android随笔
  5. Android(安卓)View 绘制流程之三:draw绘制
  6. Android(安卓)shape方法绘制图形的方法和属性解析
  7. android酷炫翻页效果+图形分析
  8. Android(安卓)OpenGL ES 开发教程 从入门到精通
  9. Android使用AchartEngine绘制曲线图

随机推荐

  1. Android的一些开源库
  2. [android]-记录日志到sd卡
  3. Android反射机制详解
  4. android代码实现ScaleAnimation动画(附原
  5. android 文档民间翻译版本
  6. Android prototype Q&A video and transc
  7. Android 简单购物车
  8. 38 Android actionbar 简单使用
  9. android正确使用killProcess完全退出应用
  10. android的四种点击事件的设置