English 中文(简体)
请帮助我达到动物群和缩放
原标题:Bitmap not zooming only dragging is happening please help me to attain zoomin and zoomout
  • 时间:2012-05-28 12:52:46
  •  标签:
  • android

hi am new to android platform in my code only dragging is happening and zooming not occurs please help me

这是使用代码的代码

@Override
public void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub



    canvas.drawBitmap(image, getBounds().left,getBounds().top, new Paint());



}

/* (non-Javadoc)
 * @see com.simplogics.surfaceview.Views.BaseView#onTouchEvent(android.view.MotionEvent)
 */


static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;


@Override

public boolean onTouchEvent(MotionEvent event) {
    boolean handled = false;

    Log.d("SimpEditText", "(int)event.getX() " + (int)event.getX());
    Log.d("SimpEditText", "(int)event.getY() " + (int)event.getY());

    if(isTouchedInBounds((int)event.getX(), (int)event.getY())){
        Log.d("SimpEditText", "Touched in Bounds");
        handled = true;
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            savedMatrix.set(matrix);
            start.set(event.getX(), event.getY());
            lastPosition.x = getBounds().left;
            lastPosition.y = getBounds().top;
        //  initialRotation = rotation(event);
            Log.d("VerticalLabelView", "mode=DRAG");
            mode = DRAG;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mode = ZOOM;

            initialScale = spacing(event);
            midPoint(mid, event);
            Log.d("VerticalLabelView", "mode=ZOOM");
            initialRotation = rotation(event);

            break;
        case MotionEvent.ACTION_UP:
            mode = NONE;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            Log.d("VerticalLabelView", "mode=NONE");
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == DRAG) {
                int x = (int)(event.getX() - start.x);
                int y = (int)(event.getY() - start.y);
                setPosition((int)lastPosition.x + x, (int)lastPosition.y + y);



            }else if(mode == ZOOM){

                currentScale = spacing(event);

                float scale =currentScale/initialScale;

                currentRotation = rotation(event);
                float angle = currentRotation - initialRotation;
                if(getImage().getWidth()> 100 && image.getWidth() <900){
                    /*Matrix testMatrix = new Matrix();
                    testMatrix.postScale(scale, scale,mid.x,mid.y);*/
                /*  rotatedImage = Bitmap.createBitmap(getImage(), 0, 0, (int)(image.getWidth()*scale),
                            (int)(image.getHeight()*scale), testMatrix, true);
                */
                    rotatedImage = Bitmap.createScaledBitmap(getImage(), (int)(image.getWidth()*scale), 
                        (int)(image.getHeight()*scale), true);
                setScale(getBounds().left,getBounds().top
                        , (int)(getImage().getWidth()*scale), (int)(getImage().getHeight()*scale));

                /*rotatedImage =rotate(angle, image);
                Matrix testMatrix = new Matrix();
                testMatrix.postScale(scale, scale,mid.x,mid.y);
                this.image = rotatedImage;
                rotatedImage = Bitmap.createScaledBitmap(image, (int)(image.getWidth()*scale), 
                        (int)(image.getHeight()*scale), true);
                this.image = rotatedImage;*/
                /*Matrix testMatrix = new Matrix();
                testMatrix.postScale(scale, scale,mid.x,mid.y);*/
            //  this.image = rotatedImage;
                /*rotatedImage = Bitmap.createScaledBitmap(image, (int)(image.getWidth()*scale), 
                        (int)(image.getHeight()*scale), true);
                this.image = rotatedImage;*/
                }

                this.image = rotatedImage;
            }
            break;
        }


    }


    return handled;

}

这是我用过的 在线拖线和触摸活动的方法

帮帮我...

问题回答

Hy 尝试 < a href=> "http://vmustafayev4en.blogspot.com/2011/12/and midal-imageview-zoom-in-zoom-out.html" rel="无跟踪" 辅导,找出你的问题所在:

使用此教程您可以学习许多特性, 例如 :

  1. drag an image
  2. Zoom in with pinch zoom (two fingers)
  3. Zoom out with pinch zoom (two fingers)

希望那些你正在寻找的东西





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签