【问题标题】:wrong value for getX() & getY() when rotate view by pinch not activity通过捏而不是活动旋转视图时getX()和getY()的错误值
【发布时间】:2018-05-09 15:43:46
【问题描述】:

这就是我想要做的。

我有一个相机视图,用户可以执行一些过程(缩放移动旋转

当用户捕获图像时,我需要将其与相机视图上的应用程序放在相机框的相同位置

我这样做如下

mCameraView 是相机视图,mCaptureImage 是预览图像

    float x = mCameraView.getX();
    float y = mCameraView.getY();

    mCaptureImage.setX(x);
    mCaptureImage.setY(y);

    float angel = mCameraView.getRotation();
    mCaptureImage.setRotation(angel);

    float scaleX, scaleY;
    scaleX = mCameraView.getScaleX();
    scaleY = mCameraView.getScaleY();

    mCaptureImage.setScaleX(scaleX);
    mCaptureImage.setScaleY(scaleY);

如果用户不旋转盒子,一切都很好

但是,如果用户旋转盒子,我会得到错误的 x,y 值,我不知道为什么会发生这种情况,并且图像会跳转到未指定的位置

我做了调试,发现旋转视图时x,y值发生了变化

这是XML的代码

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/selfie_move_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">

<com.otaliastudios.cameraview.CameraView
    android:id="@+id/selfie_camera_view"
    android:layout_width="300dp"
    android:layout_height="200dp"
    android:layout_gravity="center_vertical|center_horizontal"
    android:visibility="gone"
    app:cameraCropOutput="true"
    app:cameraPlaySounds="false" />

<ImageView
    android:id="@+id/selfie_capture_image"
    android:layout_width="300dp"
    android:layout_height="200dp"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:visibility="gone" />

</FrameLayout>

Exmaple about rotation view

谁能帮我解决这个问题?

【问题讨论】:

  • 你明白这个问题了吗?视图的旋转不适用于活动
  • 你找到解决方案了吗?
  • 很遗憾,没有:(

标签: android android-studio android-camera


【解决方案1】:

屏幕的旋转将构成配置更改,这将改变“当前可用的屏幕尺寸”。为避免这种情况,您必须使用configChanges 属性自己处理配置更改并指定一个值。

听起来您应该使用“screenSize”和“orientation”值。这将导致您的 Activity 调用 onConfigurationChanged() 而不是重新创建 Activity。

注意:自己处理配置更改会使使用替代资源变得更加困难,因为系统不会自动为您应用它们。当您必须避免由于配置更改而重新启动并且不建议用于大多数应用程序时,应将此技术视为最后的手段。

有关处理配置更改的更多信息:https://developer.android.com/guide/topics/resources/runtime-changes

更多关于configChange属性:https://developer.android.com/guide/topics/manifest/activity-element#config

【讨论】:

  • 感谢您的评论和时间,但这不是我要问的,我会附上图片示例
猜你喜欢
  • 1970-01-01
  • 2011-09-08
  • 2012-05-30
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-20
  • 1970-01-01
相关资源
最近更新 更多