---
title: 转屏功能开发
description: "实现客户端横竖屏切换。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcps/boostcph/instrucstreamengine/kunpengcpsinstruction_16_0025.html
sourcePath: /source/zh/kunpengcps/boostcph/instrucstreamengine/kunpengcpsinstruction_16_0025.html
indexId: 297f74cc03cc584994064dc289db7c7aeb0d39c8b8f0277d7aaa4608b5994ede85
---
# 转屏功能开发

#### 场景介绍

实现客户端横竖屏切换。


#### 前提条件

指令流引擎启动成功。


#### 开发流程

在orientationCallback回调函数，处理转屏功能。


#### 编码实例

```
public void onVmiEngineEvent (int event, int reserved0, int reserved1, int reserved2, int reserved3) {
    if (event == InstructionEngine.VMI_ENGINE_EVENT_ORIENTATION_CHANGED) {
        engineOrientation = reserved0;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
               setRotation(engineOrientation);
            }
         });
    }
}

private void setRotation(int rotation) {
        final int rota = rotation;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (oritentation != rota) {
                    oritentation = rota;
                    switch (oritentation) {
                        case Surface.ROTATION_0:
                            // surfaceView  ui旋转
                            surfaceView.setScreenRotation(InstructionEngine.Rotation.ROTATION0);
                            // 设置屏幕的方向
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                            break;
                        case Surface.ROTATION_90:
                            surfaceView.setScreenRotation(InstructionEngine.Rotation.ROTATION90);
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

                            break;
                        case Surface.ROTATION_180:
                            surfaceView.setScreenRotation(InstructionEngine.Rotation.ROTATION180);
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                            break;
                        case Surface.ROTATION_270:
                            surfaceView.setScreenRotation(InstructionEngine.Rotation.ROTATION270);
                            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                            break;
                        default:
                            break;
                    }
                }
            }
        });
    }
```
