0

i have made a simple android painting program for learning purpose,But ontouch stroke is not drawing ,i have tried as below: main.java

package com.example.mypen;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.Menu;
import android.view.*;
import android.view.MotionEvent;

public class MainActivity extends Activity{
    private Paint paint = new Paint();
      private Path path = new Path();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(6f);
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
    }

    public void onDraw(Canvas canvas){
        canvas.drawPath(path,paint);
        }
    public boolean onTouchEvent(MotionEvent me){
        float eventX=me.getX();
        float eventY=me.getY();

        switch (me.getAction()) {
        case MotionEvent.ACTION_DOWN:
            path.moveTo(eventX, eventY);
            return true;
        case MotionEvent.ACTION_MOVE:
            path.lineTo(eventX, eventY);
            break;
        case MotionEvent.ACTION_UP:
            break;
        }
        return true;

    }

}
4

1 回答 1

1

尝试在 onTouchEvent 方法中使您的视图无效

于 2013-07-24T11:28:53.803 回答