简体   繁体   English

Android FrameLayout / ImageView旋转问题

[英]Android FrameLayout/ImageView Rotation issue

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. 我正在旋转一个包含带有图像的Imageview的FrameLayout。当我在旋转的FrameLayout上添加另一个Imageview时,添加的imageview也会像往常一样默认旋转。

To prevent this as I need the added ImageView not to be rotated,I rotate that ImageView at the reverse angle from FrameLayout. 为了防止这种情况,因为我不需要旋转添加的ImageView,所以我以与FrameLayout相反的角度旋转该ImageView。

I am rotating FrameLayout using below code: 我正在使用以下代码旋转FrameLayout:

(1)Rotate: (1)旋转:

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

(2)Flip Vertical (2)垂直翻转

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

(3)Flip Horizontal (3)水平翻转

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

I am rotating ImageView using following code: 我正在使用以下代码旋转ImageView:

    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. 现在我面临的问题是,当我第一次旋转框架(270度),然后垂直翻转(180度),并且在将ImageView添加到该旋转的框架之后,它也旋转了ImageView。

Here I am attaching images as well. 在这里,我还要附加图像。 This is the issue 这是问题

在此处输入图片说明

I need solution like this 我需要这样的解决方案

在此处输入图片说明

Any help/suggestions will be highly appreciated. 任何帮助/建议将不胜感激。

Thanks in advance 提前致谢

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, 我的Java代码是

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... 希望这个能对您有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM