在android中绘制一个点后缩放图像

时间:2014-07-18 12:50:59

标签: android

我制作了一个应用程序,在我点击的图像上绘制一个点。现在我想添加缩放放大和缩小和拖动功能。最好的方法是什么? 提前致谢 这是我的主要活动

public class MainActivity extends ActionBarActivity {

    private RelativeLayout rl_Main;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rl_Main = (RelativeLayout) findViewById(R.id.rl_main);
        rl_Main.addView(new MyView(this));

    }

    class MyView extends View{


        Paint paint = new Paint();
        Point point = new Point();
        public MyView(Context context) {
            super(context);
            paint.setColor(Color.RED);
            paint.setStrokeWidth(15);
            paint.setStyle(Style.STROKE);
        }

        @Override
        protected void onDraw(Canvas canvas) {
              Bitmap b=BitmapFactory.decodeResource(getResources(), R.drawable.josepg);
              canvas.drawBitmap(b, 0, 0, paint);
              canvas.drawCircle(point.x, point.y, 1, paint);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                point.x = event.getX();
                point.y = event.getY();

            }
              invalidate();
            return true;

        }

    }
     class Point {
            float x, y;
        }

0 个答案:

没有答案