我想让我的应用程序只在 android 中横向 [英] i want to make my application only in landscape in android
问题描述
我想让我的应用程序只能在横向模式下运行,但无法运行.我已经给了 screenOrientation = "landscape"
即使第一页将处于横向模式而其他活动将处于纵向模式.
I want to make my app work only in landscape mode but can't make it work. I have given screenOrientation = "landscape"
even though the first page will be in landscape mode and other activity will be in portrait.
XML 文件
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name"
android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".IntroHome"
android:label="@string/app_name"
android:screenOrientation="landscape">
</activity>
<activity android:name=".ObjectivesPage"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
<activity android:name=".MenuPage"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
</application>
Java 类
public class ObjectivesPage extends Activity{
ImageButton imgButton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.objectivespage);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
imgButton = (ImageButton)findViewById(R.id.buttonCloseNGo);
imgButton.setOnClickListener(onClickCloseNGo);
}
private OnClickListener onClickCloseNGo = new OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(ObjectivesPage.this,MenuPage.class);
startActivity(intent);
}
};
}
推荐答案
保持清单的这部分原样.例如,考虑 IntroHome 活动.
Keep this part of the manifest as it already is. For example, consider the IntroHome activity.
<activity android:name=".IntroHome"
android:label="@string/app_name"
android:screenOrientation="landscape"
>
</activity>
对于活动 XML,请确保 layout-land 文件夹中有 IntroHome 活动布局 XML仅.这样,您拥有的活动将只显示您定义的 XML 的横向版本.
And for the activity XML, make sure you have the IntroHome activity layout XML only in the layout-land folder. This way, the activity / activities you have will only show the the landscape version of the XML that you have defined.
这篇关于我想让我的应用程序只在 android 中横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!