Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zooming and Panning of view in android

Hi friends I am creating one app where i put two views. first is imageview and the other one is my customeview.

i am drawing image on my custom view. my custom view code is as follow

public class DrawView extends ImageView{
    @SuppressWarnings("unused")
    private static final String TAG = "DrawView";
    Painter painter = new Painter();
    PathStack pathStack;
    private DrawApplication drawApplication;

    public DrawView(Context context, AttributeSet attr) {
        super(context,attr);
        setFocusable(true);
        setFocusableInTouchMode(true);
        drawApplication=(DrawApplication)context.getApplicationContext();
        pathStack=drawApplication.getPainter().getPathStack();
        painter=drawApplication.getPainter();
        setScaleType(ScaleType.MATRIX);

    }

    @Override
    public void onDraw(Canvas canvas) {
        float scaleFactor=drawApplication.getScaleFactor();
        canvas.scale(scaleFactor, scaleFactor,(float)getWidth()/2,(float)getHeight()/2);
        List<DrawingPath> currentStack=pathStack.getCurrentStack();

        for (DrawingPath drawPath : currentStack) {
            drawPath.draw(canvas, painter);

        }

    }
}

many things clear from code like storing path on drawapplication etc.

now we have decided to provide zooming and panning to this view. and my drawing should also be zoomed accordingly along with imageview which in back.

also i should be able to draw correctly.

I tried canvas scaling but that is worst, because after scaling i am not able to draw to the touched point and also less drawing to the screen resulting in more drawing to the view.

drawing on widget is also very lengthy task results in performance slow down. plz provide any way.

and also i am using api level 10.

Edit1

Well friends. i got one idea. i have to draw path on different zoom level. so if we can calculate path ratio in different zoom level than it will solve my problem. plz provide help accordingly

Edit2

if we will be able to scale path then it can solve my problem

Edit3

i think if we draw it on bitmap than i can achieve my goal, but my problem is resizing bitmap and providing scrolling to bitmap on different zoom level

like image 662
Sunil Pandey Avatar asked Apr 07 '11 08:04

Sunil Pandey


1 Answers

Similar questions on SO:

  • android pinch zoom
  • Pinch zoom for custom view

Can be done on Honeycomb (API lvl 11) but not properly before.

like image 53
Vincent Mimoun-Prat Avatar answered Sep 30 '22 12:09

Vincent Mimoun-Prat