Android 相机 SurfaceView 方向
我正在构建一个使用 Android 相机的应用程序。我使用有 2 个子级的 FrameLayout。第一个子项是预览相机的 SurfaceView,第二个子项是带有一些按钮的 LinearLayout。
我读到在 Android 2.1 及更低版本中,使用相机的唯一方法是在横向模式下,所以我使用 android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"
在我的清单文件中的活动中。
有没有办法仅在横向模式下使用 SurfaceView (相机),并在纵向/横向模式下使用 LinearLayout (按钮)?
(例如,在 Google Goggles 中,相机不会改变方向,但按钮会在改变方向时旋转。)
I am building an app that uses the android camera. I use a FrameLayout that has 2 children. The first child is a SurfaceView that previews the Camera and the second child is a LinearLayout with some buttons.
I have read that in Android 2.1 and below, the only way to use the camera is on Landscape mode, so I useandroid:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"
in my activity in the manifest file.
Is there a way to use the SurfaceView (camera) in landscape mode only, and use the LinearLayout (buttons) either portrait/landscape?
(For example in Google Goggles the camera doesn't change orientation but the buttons rotate when changing orientation.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 中包含的相机应用程序位于 AOSP 中。自己检查一下来源。从它的外观来看,它在横向模式下也是固定的,但只是在用户更改方向时旋转 ImageView。
请参阅 Camera 源代码的这一部分。
The Camera app included in Android is in AOSP. Check the source out for yourself. From the looks of it, it's fixed in landscape mode as well, but simply rotates the ImageViews when the user changes the orientation.
See this part of Camera's source.
最好的解决方法就像 AOSP 那样,通过使用 RotateImageView 和特殊的 ImageView 来设置旋转角度。
因此,在您的相机活动中,您必须实现 OrientationListener 并在 onOrientationChanged 上将新的度数设置为 RotateImageView。这是简单的方法,但您可以在相机实现中查找更好的示例,网址为
The best way to solve is like AOSP does by using RotateImageView and special ImageView that you can set a rotation in degrees.
So in your Camera Activity you have to implement OrientationListener and onOrientationChanged you set the new Degrees to your RotateImageView. Here is the simple way but you can look for a better example at Camera implementation at