6

I've customized imageview but its just rotating its bitmap not the whole view. I don't want to use animation because I'm dragging imageview as well so moving animated imageivew results weird, so sticking to onDraw/draw, plus overriding draw is nothing doing special.

        @Override
        protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        canvas.save();
        canvas.rotate(rotationAngle, rotationW, rotationH);
        super.onDraw(canvas);
        canvas.restore();
        }    

how can I rotate the whole view not only its bitmap??

Khawar
  • 859
  • 11
  • 30

3 Answers3

4

I did not get the provided answers intend here, but using

android:clipChildren="false"

for the parent ViewGroup and overriding draw instead of onDraw did the job for me

For further information see: Rotating imageview and its background without cropp

Community
  • 1
  • 1
Murmel
  • 5,402
  • 47
  • 53
1
  1. One must check width and height of the imageview, if Height > width then at the time of rotation width must be equal to height and same with height.

  2. Make width and height equal to fill_parent and then rotate/translate/scale via matrix.

patridge
  • 26,385
  • 18
  • 89
  • 135
Khawar
  • 859
  • 11
  • 30
0

Starting with API 11, there is the following method available for each view:

.setRotation(float angle);

http://developer.android.com/reference/android/view/View.html#attr_android:rotation


Before API 11 you could add a rotate to the main-element of your view:

@Override
protected void onDraw(Canvas c) {
  c.save();
  c.rotate(...);
  super.onDraw(c);
  c.restore();
}
patridge
  • 26,385
  • 18
  • 89
  • 135
Nippey
  • 4,708
  • 36
  • 44
  • There is no difference between code we both posted, actually I'm doing the same thing and its working but its cutting its edges unless its on 0'/180'/360'. – Khawar Sep 14 '12 at 07:15
  • But do you do it on the image view or on the complete window? You can take the main container-element and turn everything. That was my thougt :) – Nippey Sep 14 '12 at 07:46
  • I've multiple imageview in relativeLayout, so user tap on any of the view and then rotate/scale that view(imageview/textview), so how can I rotate the whole layout? that's why I've customized imageview but can't rotate actual container of imageview, I can't post snap of emulator so that why you are not getting it, hope you got my point :) – Khawar Sep 14 '12 at 08:07