【问题标题】:Android FrameLayout/ImageView Rotation issueAndroid FrameLayout/ImageView 旋转问题
【发布时间】:2015-10-17 12:38:49
【问题描述】:

我正在旋转一个 FrameLayout,其中包含一个带有图像的 Imageview。当我在该旋转的 FrameLayout 上添加另一个 Imageview 时,添加的 imageview 也会像往常一样默认旋转。

为了防止这种情况发生,因为我需要添加的 ImageView 不被旋转,我以与 FrameLayout 相反的角度旋转该 ImageView。

我正在使用以下代码旋转 FrameLayout:

(1)旋转:

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

(2)垂直翻转

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

(3)水平翻转

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

我正在使用以下代码旋转 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()));
    }

现在我面临的问题是,当我第一次旋转框架(270 度),然后垂直翻转(180 度)并在该旋转框架中添加 ImageView 后,它也会旋转 ImageView。

这里我也附上图片。 这就是问题

我需要这样的解决方案

任何帮助/建议将不胜感激。

提前致谢

【问题讨论】:

  • 不要在同一个框架内添加第二个视图怎么样,因为你不想旋转它而只是显示它?相反,您可以将其放在具有透明背景的附加浮动视图中,您尝试过吗?
  • @mass,我需要旋转第二个视图以及同一个框架,因此我在同一个框架内添加第二个视图。但是如果框架已经旋转并且发生了这种情况,第二个视图会旋转仅在我上面描述的场景中。
  • 对不起,我不清楚你想做什么。你想独立旋转第二个图像视图吗?或者你的问题是你的第二个图像视图一旦你添加到视图中就会旋转,因为视图已经旋转了?这对我来说似乎很直观。为什么不跟踪原始框架的旋转?如果你更详细地解释你真正想要的东西,我会帮助你。

标签: android image rotation android-imageview android-framelayout


【解决方案1】:

我的 Framelayout 就像..

<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>

我的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);

希望对你有帮助……

【讨论】:

  • 独立旋转两个图像视图我没有找到一个好主意,因此我旋转了框架。
  • 好的...然后做一件事...当您将框架旋转 180 度时...将第二张图像以相同的度数反向旋转...然后它看起来会正确..
  • 我已经这样做了,但这不起作用。 if(mainFrm.getRotationX()!=0) { iv.setRotationX(-(mainFrm.getRotationX())); }
  • 我做了和我上面提到的一样的事情。我得到了正确的结果......正如你所期望的......你想要样品......??
  • 是的,提前致谢。 :)
猜你喜欢
  • 1970-01-01
  • 2018-02-03
  • 2012-09-20
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
  • 2014-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多