Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

i want to make my application only in landscape in android

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);
        }
    };
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...