Wednesday, October 5, 2011

[android-developers] Re: Rotate A View Permanently

I'm  struggling trying to rotate by 180 degrees, a ViewGroup which contains buttons and checkboxes.  Does anyone have a reliable way of doing this?  I've been able to get what's rendered to the screen to be rotated, but the touch event coordinates seem off and the dynamic widget elements (the highlighting and check marks for example, don't seem to be rotated-- at last not correctly).

Is there a setting that I'm missing in the ViewGroup?  Any other ideas?

I had to modify the originally posted code as follows:

        public FlipLayout(Context context) {
            super(context);
            //mForward.setScale(1, 1);
            //mForward.setRotate(0);
            //mForward.invert(mReverse);         
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {  //dispatchDraw
            /*
            canvas.save();
            canvas.setMatrix(mForward);
            super.dispatchDraw(canvas);
            canvas.restore();
            */
        
            canvas.rotate(180, getWidth()/2, getHeight()/2);
           
            mForward = canvas.getMatrix();
            //mForward.invert(mReverse);
            canvas.save();
            canvas.setMatrix(mForward); //This is the matrix we need to use for proper positioning of touch events
            super.dispatchDraw(canvas);
            canvas.restore();
           

        }

        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            final float[] temp = mTemp;
            temp[0] = event.getX();
            temp[1] = event.getY();

            //mReverse.mapPoints(temp);

            //event.setLocation(temp[0], temp[1]);
            event.setLocation(getWidth()-temp[0], getHeight()-temp[1]);
            return super.dispatchTouchEvent(event);
        }
    }


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment