繁体   English   中英

如何为相机设置android:screenOrientation =“ portrait”

[英]How to set android:screenOrientation=“portrait” for Camera

我正在使用Samsung Galaxy Note运行phonegap应用程序。 拍照时,可以看到屏幕在进入相机之前旋转。 如何禁用此功能?

我试图在主线程和相机活动上都强制使用纵向方向,但是这些似乎不起作用:

<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:debuggable="true">
    <activity android:name=".App" android:windowSoftInputMode="adjustPan" android:screenOrientation="portrait"
              android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
              android:configChanges="orientation|keyboardHidden">
        <intent-filter>
        </intent-filter>
    </activity>
    <activity android:name="com.android.camera.Camera"
            android:screenOrientation="portrait">
    </activity>
</application>

您需要在清单上添加权限:

<uses-feature android:name="android.hardware.screen.portrait" />

Balise用途的Doc Android

例如,如果您的应用程序要求纵向设置,则应声明<uses-feature android:name="android.hardware.screen.portrait"/>以便只有支持纵向设置的设备(无论是始终使用还是通过用户选择)都可以安装您的应用。 如果您的应用程序同时支持这两种方向,则无需声明任何一种。

你怎么拍照? 如果发送意向启动相机应用程序,则您将失去方向更改的控制权。 还要注意,在进入睡眠状态并锁定屏幕启动器之前,您的应用程序会以设置或替代方法的对接方式进入纵向。 很可能您不能这样做,并且其他设备上的行为可能有所不同。

这里有两件事要考虑。 首先,这个

android:screenOrientation="landscape"

如果在Java代码中有以下内容,则无效:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

然后,还有另一种方法可能会困扰您:

mCamera.setDisplayOrientation(90);

这将旋转您的相机预览。

希望这可以帮助!

使用android:configChanges="orientation|keyboardHidden"将屏幕设置为纵向。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM