我想让我的应用程序只有在景观的android [英] i want to make my application only in landscape in android

查看:100
本文介绍了我想让我的应用程序只有在景观的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的应用程序的工作只能在横向模式,但不能使它发挥作用。我已经给 screenOrientation =景观即使第一页将在风景模式和其他活动将会在肖像。

XML文件

 <应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:主名称=
              机器人:标签=@字符串/ APP_NAME
              机器人:screenOrientation =景观安卓主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>

    < /活性GT;

    <活动机器人:名称=。IntroHome
              机器人:标签=@字符串/ APP_NAME
              机器人:screenOrientation =景观与GT;
    < /活性GT;

    <活动机器人:名称=。ObjectivesPage
              机器人:标签=@字符串/ APP_NAME
              机器人:screenOrientation =景观与GT;
    < /活性GT;

    <活动机器人:名称=。MenuPag​​e
              机器人:标签=@字符串/ APP_NAME
              机器人:screenOrientation =景观与GT;
    < /活性GT;
< /用途>
 

 

JAVA CLASS

 公共类ObjectivesPage延伸活动{

    的ImageButton imgButton;
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.objectivespage);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        imgButton =(的ImageButton)findViewById(R.id.buttonCloseNGo);
        imgButton.setOnClickListener(onClickCloseNGo);
    }

    私人OnClickListener onClickCloseNGo =新OnClickListener(){

        公共无效的onClick(视图v){
            意向意图=新的意图(ObjectivesPage.this,MenuPag​​e.class);
            startActivity(意向);
        }
    };
}
 

解决方案

请这部分的表现,因为它已经是了。例如,考虑IntroHome活动。

 <活动机器人:名称=。IntroHome
           机器人:标签=@字符串/ APP_NAME
           机器人:screenOrientation =风景
           >
< /活性GT;
 

和对活动的XML,请确保您有IntroHome活动布局XML的布局土地文件夹。通过这种方式,活动/活动,你将只能说明你已经定义了XML的景观版本。

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 FILE

<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 CLASS

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);
        }
    };
}

解决方案

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>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆