如何通过默认横向设置显示旋转

问题描述 投票:0回答:1

我已经在我的应用程序中集成了cameraX,并且在清单文件中将方向设置为横向,但是预览始终显示方向肖像。如何设置默认横向的预览方向?

机器人:screenOrientation = “风景”

以上参数已设置为清单。

android android-layout landscape android-camerax
1个回答
0
投票

更改屏幕方向不会改变相机方向。

setOnPreviewOutputUpdateListener {
     texture.surfaceTexture = it.surfaceTexture
     updateTransform()
}

并调用上述方法以显示视图。

val matrix = Matrix()
val centerX = texture.width / 2f
val centerY = texture.height / 2f

val rotationDegrees = when (texture.display.rotation) {
     Surface.ROTATION_0 -> 0
     Surface.ROTATION_90 -> 90
     Surface.ROTATION_180 -> 180
     Surface.ROTATION_270 -> 270
     else -> return
}

matrix.postRotate(-rotationDegrees.toFloat(), centerX, centerY)
texture.setTransform(matrix)

此纹理设置为TextureView。

© www.soinside.com 2019 - 2024. All rights reserved.