gpt4 book ai didi

android - Android 6 上的 SurfaceView 旋转问题

转载 作者:行者123 更新时间:2023-12-02 10:27:50 33 4
gpt4 key购买 nike

我有一个运行 OpenCV 应用程序的简单 Activity 。应用程序应该检测来自相机的对象并在自定义 SurfaceView 上将它们可视化。我想将设备方向锁定为纵向模式,并像标准相机应用程序一样以编程方式旋转我的小部件。

这是 Activity 布局。它包括 OpenCV CameraView 和其上方显示的 fragment 小部件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.chessking.android.vision.ui.widget.ExtendedCameraView
android:id="@+id/track_camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
opencv:camera_id="any"
opencv:show_fps="true"/>

<FrameLayout
android:id="@+id/track_fragment_container"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true">

<fragment
android:id="@+id/track_board_preview"
class="com.chessking.android.vision.ui.BoardWidgetFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>

<Button
android:id="@+id/track_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="16dp"
android:text="@string/scan_action"/>
</RelativeLayout>

自定义SurfaceView呈现在 fragment 布局中。它是com.convekta.android.chessboard.ChessPanel

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/board_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/boardBackground"
android:orientation="vertical">

<include layout="@layout/widget_board_clock_both" />

<com.convekta.android.chessboard.ChessPanel
android:id="@+id/board_panel"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/board_background_transparent"
app:chessPanelBackground="@color/board_background_transparent"
app:chessPanelBorderColor="@color/board_border"
app:chessPanelBorderWidth="1dp"/>

<com.convekta.android.chessboard.NotationView
android:id="@+id/nota"
android:layout_width="match_parent"
android:layout_height="20dp"
android:clipChildren="false"
android:fadeScrollbars="false" />

</LinearLayout>

当我需要旋转小部件布局时,我更改 board_layoutrotation 属性。

boardLayout.rotation = degrees.toFloat()

问题是旋转可以在 Android 9 上运行,但 Canvas 在 Android 上错位。以下是 Android 6 模拟器的屏幕截图,在纵向模式下应用程序看起来很正常,在横向模式下 SurfaceView 会跳出其布局。 Portrait mode Landscape mode

最佳答案

<activity>标签 AndroidManifest.xml ,添加行 android:screenOrientation="portrait"

关于android - Android 6 上的 SurfaceView 旋转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60722010/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com