2013-02-21 2 views
0

현재 내 앱에서 화면에 표시하고 있습니다. 사용자는 집의 방을 나타내는 직사각형을 그릴 수 있지만 현재는 초기 공간으로 제한됩니다.화면에 그리기 - 확대/축소 할 수 있어야합니다.

사용자가 화면을 스크롤하고 확대/축소 할 수있는 더 큰 캔버스에 화면을 단순히 "창"으로 만드는 가장 좋은 방법은 무엇입니까?

class HomerView extends View { // the custom View for drawing on 
    // set up Bitmap, canvas, path and paint 
    private Bitmap myBitmap; // the initial image we turn into our canvas 
    private Canvas myCanvas; // the canvas we are drawing on 
    private Rect myRect; // the mathematical path of the lines we draw 
    private Paint myBitmapPaint; // the paint we use to draw the bitmap 

    // get the width of the entire tablet screen 
    private int screenWidth = getContext().getResources() 
      .getDisplayMetrics().widthPixels; 
    // get the height of the entire tablet screen 
    private int screenHeight = getContext().getResources() 
      .getDisplayMetrics().heightPixels; 

    public HomerView(Context context) { // constructor of HomerView 
     super(context); 
     myBitmap = Bitmap.createBitmap(screenWidth, screenHeight, 
       Bitmap.Config.ARGB_8888); // set our drawable space - the bitmap which becomes the canvas we draw on 
     myCanvas = new Canvas(myBitmap); // set our canvas to our bitmap which we just set up 
     myRect = new Rect(); // make a new rect 
     myBitmapPaint = new Paint(Paint.DITHER_FLAG); // set dither to ON in our saved drawing - gives better color interaction 
    } 

    protected void onDraw(Canvas canvas) { // method used when we want to draw something to our canvas 
     canvas.drawColor(Color.TRANSPARENT); // sets canvas colour 
     canvas.drawBitmap(myBitmap, 0, 0, myBitmapPaint); // save the canvas to bitmap - the numbers are the x, y coords we are drawing from 
     canvas.drawRect(myRect, myPaint); // draw the rectangle that the user has drawn using the paint we set up 
    } 

    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) { // if screen size changes, alter the bitmap size 
     super.onSizeChanged(w, h, oldw, oldh); 
     /*myBitmap = Bitmap.createBitmap(screenWidth, screenHeight, 
       Bitmap.Config.ARGB_8888); 
     myCanvas = new Canvas(myBitmap);*/ 
    } 

      public void drawApplianceIcon() { 
     myCanvas.drawBitmap(bmp, iX - 50, iY - 50, myBitmapPaint); 
     makeToast("Lamp Drawn To Canvas"); 
    } 


    // these variables are needed in touch listening 
    private int mX, mY, iX, iY; // current x,y and initial x,y 
    private static final float TOUCH_TOLERANCE = 4; 

private void touch_start {} // touch methods 
private void touch_move {} 
private void touch_up {} 

이 같이에서 onCreate에 선언 : 는 또한

(I는 "도면"터치 모드와 "이동"터치 모드가있을 것 감사), 캔버스는 커스텀 뷰 클래스입니다 이 코드는

View drawingAreaView = new HomerView(this); 
setContentView(drawingAreaView); 

어떻게 코드를 적용하여 스크롤 가능한 창으로 만들 수 있습니까?

답변

1

보기 초기화 중에 시도해보십시오.

setHorizontalScrollBarEnabled(true); 
setVerticalScrollBarEnabled(true); 

나는 당신이 또한

http://developer.android.com/reference/android/view/ScaleGestureDetector.html 그리고 모든 위치를 보유하고 뷰포트 로직의 어떤 종류가 필요합니다 같아요.

이 또한 찾았습니다.

Android: Enable Scrollbars on Canvas-Based View

+0

도움 주셔서 감사합니다! 뷰포트 란 무엇입니까? 내가 게시 한 자료를 살펴 보겠습니다. –

+0

보기 영역입니다. 나는 canvas.translate를 사용할 수 있다고 생각합니다. –

관련 문제