1

I am rotating a FrameLayout which contains an Imageview with image.When I add another Imageview on that rotated FrameLayout than the added imageview also get rotates by default as usual.

To prevent this as I need the added ImageView not to be rotated,I rotate that ImageView at the reverse angle from FrameLayout.

I am rotating FrameLayout using below code:

(1)Rotate:

    float angle = mainFrm.getRotation();
    if (angle == 0) {
        angle = 360;
    }
    angle = angle - 90;
    mainFrm.setRotation(angle);

(2)Flip Vertical

    float angle = mainFrm.getRotationX();
    if (angle == 0) {
        angle = 360;
    }
    angle = angle - 180;
    mainFrm.setRotationX(angle);

(3)Flip Horizontal

    float angle = mainFrm.getRotationY();
    if (angle == 0) {
        angle = 360;
    }
    angle = angle - 180;
    mainFrm.setRotationY(angle);

I am rotating ImageView using following code:

    if(mainFrm.getRotation()!=0)
    {
        iv.setRotation(-(mainFrm.getRotation()));
    }
    if(mainFrm.getRotationX()!=0)
    {
        iv.setRotationX(-(mainFrm.getRotationX()));
    }
    if(mainFrm.getRotationY()!=0)
    {
        iv.setRotationY(-(mainFrm.getRotationY()));
    }

Now the issue I am facing is when I first rotate frame(270 degree),then flip it vertically(180 degree) and after add an ImageView to that rotated frame it rotates the ImageView as well.

Here I am attaching images as well. This is the issue

enter image description here

I need solution like this

enter image description here

Any help/suggestions will be highly appreciated.

Thanks in advance

Nitesh
  • 263
  • 7
  • 22
  • How about not adding the second view inside the same frame, since you dont want to rotate it but only to display it? Instead you could put it in an additional floating view with transparent backgroud, did you give that a try? – Kerem Oct 23 '15 at 09:01
  • @mass, I need to rotate the second view as well along with same frame hence I am adding the second view inside the same frame.But the second view got rotated if frame is already rotated and this happened only in the scenario I described above. – Nitesh Oct 23 '15 at 09:06
  • Im sorry its not clear for me what you want to do. Do you want to rotate the second image view independently? Or your problem is that your second image view gets rotated once you add it to the view, because the view is already rotated? That seems intuitive to me. Why dont you track the rotations of the original frame? If you explain what you really want with a bit more detail, i will help you. – Kerem Oct 23 '15 at 21:17

1 Answers1

0

My Framelayout is like..

<FrameLayout android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="#33ffff">
    <ImageView android:id="@+id/image1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher"/>

    <ImageView android:id="@+id/image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:src="@drawable/ic_launcher"/>
</FrameLayout>

and my java code is,

mFrame = (FrameLayout) findViewById(R.id.frame);
    mImage1 = (ImageView) findViewById(R.id.image1);
    mImage2 = (ImageView) findViewById(R.id.image2);
    float angle = mFrame.getRotation();
    if(angle == 0) {
        angle = 180;
    }
    mFrame.setRotation(angle);
    mImage2.setRotation(-angle);

Hope this will help you...

Vennila
  • 240
  • 1
  • 11
  • Rotating two imageviews independently I didn't found a good idea hence I have rotated frame. – Nitesh Oct 23 '15 at 09:32
  • okay... then do one thing... while you rotating the frame by 180 degree... rotate the second image in the reverse direction with the same degree... then it will look correct.. – Vennila Oct 23 '15 at 10:08
  • I have already did that but that's not working. if(mainFrm.getRotationX()!=0) { iv.setRotationX(-(mainFrm.getRotationX())); } – Nitesh Oct 23 '15 at 10:09
  • I done the same as I mentioned above.. I got the correct result... as you expected... Do you want the sample..?? – Vennila Oct 23 '15 at 10:25
  • Yes,Thanks in advance. :) – Nitesh Oct 23 '15 at 10:27
  • Your code will rotate image to 180.It will not flip.Hence this is not useful in my case.Thanks:) – Nitesh Oct 23 '15 at 10:34