Android 无法设置屏幕方向,
Android cannot set screenOrientation,
我已经通读了所有 post 我能在这个网站和其他网站上找到的内容并听从了建议,但在最简单的实现中,我无法将 Note 5 设置为人像模式,当它处于物理状态时横向方向。
我将建议的行添加到清单文件,重新构建,应用程序以横向模式启动。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twistlogic.miwidget">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我也试过用代码来做这件事,这是我的主要目的:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
没有什么是有效的。
我正在努力学习 Android 所以我明白这很可能是因为我的知识有限。我想做的是固定方向并将其锁定在那里,然后仅在用户按下按钮时才允许它更改。我确实读到必须在 API 13 之后设置屏幕尺寸。但我不确定如何设置。我正在使用创建项目时来自基本活动的片段模板屏幕。
感谢您的帮助。
这个可以在Main里设置Activity我没试过在Manifest里设置这里是一行代码几行写个测试ok这里是Manifest代码在结束
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
在您的清单文件中,在您的主要 activity 行下方粘贴。
android:屏幕方向="portrait"
我没有在清单文件中测试过这段代码
我已经通读了所有 post 我能在这个网站和其他网站上找到的内容并听从了建议,但在最简单的实现中,我无法将 Note 5 设置为人像模式,当它处于物理状态时横向方向。 我将建议的行添加到清单文件,重新构建,应用程序以横向模式启动。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twistlogic.miwidget">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我也试过用代码来做这件事,这是我的主要目的:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
没有什么是有效的。
我正在努力学习 Android 所以我明白这很可能是因为我的知识有限。我想做的是固定方向并将其锁定在那里,然后仅在用户按下按钮时才允许它更改。我确实读到必须在 API 13 之后设置屏幕尺寸。但我不确定如何设置。我正在使用创建项目时来自基本活动的片段模板屏幕。
感谢您的帮助。
这个可以在Main里设置Activity我没试过在Manifest里设置这里是一行代码几行写个测试ok这里是Manifest代码在结束
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
在您的清单文件中,在您的主要 activity 行下方粘贴。
android:屏幕方向="portrait"
我没有在清单文件中测试过这段代码