I'm following the CameraX codelab and I'm getting a wrong aspect ratio on the preview even using setTargetAspectRatio
and setTargetResolution
methods.
private fun startCamera() {
// Create configuration object for the viewfinder use case
val previewConfig = PreviewConfig.Builder().apply {
setTargetAspectRatio(Rational(1, 1))
setTargetResolution(Size(640, 640))
}.build()
...
And the layout is using a hardcoded size as presented in the codelab.
<TextureView
android:id="@+id/view_finder"
android:layout_width="640px"
android:layout_height="640px"
...
It would be nice if the library had CameraTextureView
and a property android:scaleType
(similar to the existing for the ImageView
) to adjust the preview to the preview size.