【问题标题】:Android Camera SurfaceView OrientationAndroid相机SurfaceView方向
【发布时间】:2011-03-24 20:30:05
【问题描述】:

我正在构建一个使用 android 相机的应用程序。我使用有 2 个孩子的 FrameLayout。第一个孩子是预览相机的 SurfaceView,第二个孩子是带有一些按钮的 LinearLayout。

我读过在 Android 2.1 及更低版本中,使用相机的唯一方法是在横向模式下,所以我使用 android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation" 在清单文件中的我的活动中。

有没有办法只在横向模式下使用 SurfaceView(相机),而纵向/横向使用 LinearLayout(按钮)?

(例如,在 Google Goggles 中,相机不会改变方向,但按钮会在改变方向时旋转。)

【问题讨论】:

    标签: android layout camera orientation landscape


    【解决方案1】:

    Android 中包含的相机应用位于 AOSP 中。自己检查一下来源。从外观上看,它在横向模式下也是固定的,但只是在用户改变方向时旋转 ImageViews。

    查看相机来源的this part

    【讨论】:

      【解决方案2】:

      解决的最佳方法是像 AOSP 一样,使用 RotateImageView 和特殊的 ImageView,您可以设置旋转度数。 因此,在您的相机活动中,您必须实现 OrientationListener 和 onOrientationChanged,您将新的度数设置为您的 RotateImageView。这是简单的方法,但您可以在

      上的相机实现中寻找更好的示例
      private class MyOrientationEventListener extends OrientationEventListener {
              public MyOrientationEventListener(Context context) {
                  super(context);
              }
      
              @Override
              public void onOrientationChanged(int orientation) {
      
      
                  mOrientation = roundOrientation(orientation);
                  ((RotateImageView)findViewById(R.id.btnFlash)).setDegree(mOrientation);
      
      
              }
          }
      
          public static int roundOrientation(int orientation) {
              return ((orientation + 45) / 90 * 90) % 360;
          }
      

      【讨论】:

        猜你喜欢
        • 2011-07-06
        • 2014-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-29
        • 2012-08-04
        相关资源
        最近更新 更多