绝对坐标机器人位图 [英] Absolute coordinates bitmap android

查看:121
本文介绍了绝对坐标机器人位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图,大小比屏幕更大(即,1000×1000)。此位图的感谢,我可以拖到画布上。如果我在点(500,500)的getX或鸵鸟政策的getY返回500否则为0和320的屏幕尺寸模拟器]之间的一些价值,所以我需要知道关于绝对值指向0。我希望我的视图不转换位图比视图的0左和0前点多了。

I have a bitmap with a size greater than screen (i.e, 1000x1000). I can drag this bitmap thanks to canvas. If i am in the point (500,500) getX or getY don´t return 500 else some value between 0 and 320[screen size emulator], so I need to know the absolute value with respect to point 0. I want my View not to translate the bitmap more than the 0 Left and 0 Top points of the View

我把一些code,以澄清问题

I put some code to clarify the question

public MapaView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mSurfaceHeight = 640;
    mSurfaceWidth = 480;
    mapaActual = new Mapa();
    mContext = context;
    mBufferedCanvas = new Canvas();

}


    draw(Canvas c){ 

    bitmapAux.eraseColor(Color.WHITE);

   /*draw the rectangles....*/

    c.translate(mPosX, mPosY);
    c.scale(mScaleFactor, mScaleFactor);
    c.drawBitmap(bitmapAux, 0, 0, null);}

我得到下一个方法的位置

I get the position with next method

@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: {
            startTime = ev.getEventTime();
            final float x = ev.getX();
            final float y = ev.getY();
            final float xR= ev.getRawX();
            final float yR= ev.getRawY();
            movido=false;
            mLastTouchX = x;
            mLastTouchY = y;
            mLastTouchXRaw = xR;
            mLastTouchYRaw = yR;

            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;

                movido=true;
                invalidate();
            }

            mLastTouchX = x;
            mLastTouchY = y;
            movido=true;


            break;
        }

        case MotionEvent.ACTION_UP: {
            mActivePointerId = INVALID_POINTER_ID;
            endTime = ev.getEventTime();

            if ((endTime - startTime > 500)&&!movido) {

                // we have a 1000ms duration touch
                // propagate your own event
                Log.d("LC", "time touched greater than 1000ms " + endTime + "  "
                        + startTime);

                startTime = 0;
                endTime = 0;
                movido=false;
                Box pepeBox=new Box();
                pepeBox=buscarElemento();
                //Intent intent=new Intent(mContext,OpcionesConceptoList.class);
                //mContext.startActivity(intent);
                /*
                 * return true; notify that you handled this event (do not
                 * propagate)
                 */
            }
            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;
    }

任何意见?

在此先感谢,并请原谅我的英语水平。

Thanks in advance and excuse my english.

推荐答案

getRawX()和getRawY():坐标(X,Y)相对返回手机屏幕

getRawX() and getRawY() : return the coordinate(X,Y) relative to the screen of the phone

的getX()和的getY():返回coordiantes(X,Y)相对于视图

getX() and getY() : return the coordiantes(X,Y) relative to the View.

是什么?其实绝对坐标

这篇关于绝对坐标机器人位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆