How to draw a line in android

前端 未结 15 1973
野趣味
野趣味 2020-11-22 06:27

Can anybody tell how to draw a line in Android, perhaps with an example?

15条回答
  •  忘了有多久
    2020-11-22 07:04

      final SurfaceView surf = (SurfaceView)findViewById(R.id.surface_home);
                    surf.setOnTouchListener( new SurfaceView.OnTouchListener(){
                        private boolean moving = false;//stupid state
                        public boolean onTouch(View v, MotionEvent event) {
                            switch( event.getAction() ){
                            case MotionEvent.ACTION_DOWN:
                                final int x = (int)event.getX();
                                final int y = (int)event.getY();
                                final Rect bounds = mTiles.getBounds();
                                moving = bounds.intersects(x, y, x+1, y+1);
                                return true;
                            case MotionEvent.ACTION_MOVE:
                                if( moving ){
                                    final int x_new = (int)event.getX();
                                    final int y_new = (int)event.getY();
                                    mDrawTiles.draw( new DrawLogic(){
                                        public void draw(Rect _surface) {
                                            mTiles.setBounds(
                                                x_new - mDrawWidth/2,
                                                y_new - mDrawHeight/2,
                                                x_new + mDrawWidth/2,
                                                y_new + mDrawHeight/2);
                                            }
                                        });
    

提交回复
热议问题