Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7942625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:01:55+00:00 2026-06-04T00:01:55+00:00

I have Class which Extends View I’m able To Move one Image Over another

  • 0

I have Class which Extends View I’m able To Move one Image Over another For This I use Two Bitmap Image one Over Another now i want to save image’s using Double Tap event but i dnt know how to do this….can anyone have some idea or code for this ……

`public class ShowCanvas extends View {

Bitmap CanvasBitmap;
Bitmap ScaledBitmap;
Bitmap smallbitmap;
private static final int INVALID_POINTER_ID = -1;

private Drawable mImage;
private float mPosX;
private float mPosY;

private float mLastTouchX;
private float mLastTouchY;
private int mActivePointerId = INVALID_POINTER_ID;

private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;

public ShowCanvas(Context context) {

this(context, null, 0);
// TODO Auto-generated constructor stub

    ScaledBitmap = DrawView.scaled;

    mImage = new BitmapDrawable(getResources(), Dress.bitmap);


    System.out.println("MImage" +mImage);

    mImage.setBounds(0, 0, mImage.getIntrinsicWidth(),
            mImage.getIntrinsicHeight());

}

public ShowCanvas(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public ShowCanvas(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
}

public void setBitmap(Bitmap bitmap) {
    // TODO Auto-generated method stub
    CanvasBitmap = bitmap;

    System.out.println("CanvasBitmap" + CanvasBitmap);

    int X = CanvasBitmap.getHeight();
    int Y = CanvasBitmap.getWidth();

    System.out.println("CanvasBitmap " + X + "\t" + Y);

}

@Override
public boolean isLongClickable() {
    // TODO Auto-generated method stub

    System.out.println("ISLongClickable");
    return super.isLongClickable();
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    // Let the ScaleGestureDetector inspect all events.
    mScaleDetector.onTouchEvent(ev);




    final int action = ev.getAction();

    switch (action & MotionEvent.ACTION_MASK) {

    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();

        mLastTouchX = x;
        mLastTouchY = y;
        mActivePointerId = ev.getPointerId(0);


        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);
        final float x = ev.getX(pointerIndex);
        final float y = ev.getY(pointerIndex);

        // Only move if the ScaleGestureDetector isn't processing a
        // gesture.
        if (!mScaleDetector.isInProgress()) {
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;

            mPosX += dx;
            mPosY += dy;

            invalidate();
        }

        mLastTouchX = x;
        mLastTouchY = y;

        break;
    }

    case MotionEvent.ACTION_UP: {
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = ev.getPointerId(pointerIndex);
        if (pointerId == mActivePointerId) {
            // This was our active pointer going up. Choose a new
            // active pointer and adjust accordingly.
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mLastTouchX = ev.getX(newPointerIndex);
            mLastTouchY = ev.getY(newPointerIndex);
            mActivePointerId = ev.getPointerId(newPointerIndex);
        }
        break;
    }
    }

    return true;
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    Paint mpaint = new Paint();

    canvas.save();
    canvas.drawBitmap(ScaledBitmap, 0, 0, mpaint);
    Log.d("DEBUG", "X: " + mPosX + " Y: " + mPosY);
    canvas.translate(mPosX, mPosY);
    canvas.scale(mScaleFactor, mScaleFactor);
    mImage.draw(canvas);


    canvas.restore();

}

private class ScaleListener extends
        ScaleGestureDetector.SimpleOnScaleGestureListener {
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
        mScaleFactor *= detector.getScaleFactor();

        // Don't let the object get too small or too large.
        mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 10.0f));

        invalidate();
        return true;
    }
}

}`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:01:57+00:00Added an answer on June 4, 2026 at 12:01 am

    If you mean double tap you have to use GestureDetector.OnDoubleTapListener. check this link

    try this

    public class MyView extends View {
    
    GestureDetector gestureDetector;
    
    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
                // creating new gesture detector
        gestureDetector = new GestureDetector(context, new GestureListener());
    }
    
    // skipping measure calculation and drawing
    
        // delegate the event to the gesture detector
    @Override
    public boolean onTouchEvent(MotionEvent e) {
        return gestureDetector.onTouchEvent(e);
    }
    
    
    private class GestureListener extends GestureDetector.SimpleOnGestureListener {
    
        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
        // event when double tap occurs
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            float x = e.getX();
            float y = e.getY();
    
            Log.d("Double Tap", "Tapped at: (" + x + "," + y + ")");
    
            return true;
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view in Eclipse (implemented by a class which extends org.eclipse.ui.part.ViewPart )
I have class A which extends the Activity class. This class is in package
Hi Experts: I have a class which extends JPanel now ShapePanel (Sp) this gets
I have crated a class which extends the ListFragment . I have one button
I have a class which extends the TextEditor for creating an editor view. I
I have created a class (InputControl) which extends the view of my main class
I have a custom view (which extends GLSurfaceView) I'm trying to use in my
I need to have a class which extends view that overrides the onSizeChanged method
I am trying to create downloading progress. I have my class which extends AsyncTask:
I have a custom class loader which extends from a URLClassLoader. I added a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.