簡體   English   中英

Android 6 上的 SurfaceView 旋轉問題

[英]SurfaceView rotation issue on Android 6

我有一個運行 OpenCV 應用程序的簡單活動。 該應用程序應從相機檢測對象並在自定義 SurfaceView 上可視化它們。 我想在縱向模式下鎖定設備方向並像標准相機應用程序一樣以編程方式旋轉我的小部件。

這是活動布局。 它包括 OpenCV CameraView 和顯示在其上方的片段小部件。

<?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在片段布局中呈現。 它是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>

當我需要旋轉部件layour,我改變rotation的財產board_layout

boardLayout.rotation = degrees.toFloat()

問題是旋轉適用於 Android 9,但畫布在 Android 上放錯了位置。 這是來自 Android 6 模擬器的屏幕截圖,在縱向模式下,應用程序看起來很正常,在橫向模式下 SurfaceView 跳出其布局。 人像模式 橫向模式

AndroidManifest.xml<activity>標簽中,添加一行android:screenOrientation="portrait"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM