Home java Disable Activity turn and

Disable Activity turn and

Author

Date

Category

Good afternoon.

How to solve this situation?

There is an android application that depends on a single parameter – the display diagonal. This value, or approximate to it, I find – no problems.
Depending on the display & gt; 5 inches – only landscape, & lt; 5 – only portrait

.

protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    if (ScreenSize & lt; 5) {
      setContentView (R.layout.startactivity_p); // display the CML portrait
    }
    ELSE {
      setContentView (R.layout.startactivity_l); // display the CML landskeyp
    }
  }

Every xml-ordered layout to the following:

android: screenOrientation = "landscape"
Android: Orientation = "Vertical"

and

android: screenOrientation = "portrait"
android: orientation = "horizontal"

respectively.

But app turns all the same. Tell me, how can I fix it?


Answer 1, Authority 100%

For each of your case

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

and

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Do not rotated. In general, here’s a good article .


Answer 2, Authority 52%

Still, better to do it in the Manifesto.

android: screenOrientation = "portrait"

or

android: screenOrientation = "landscape"

All together:

& lt; activity android: name = "SomeActivity."
  android: label = "@ string / app_name"
  android: screenOrientation = "portrait" / & gt;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions