Question:
Good afternoon.
How to solve this situation correctly?
There is an android application that depends on one parameter – the display diagonal. This value, or approximate to it, I find – there are no problems. Depending on the display,> 5 "landscape only, <5" portrait only.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (ScreenSize<5) {
setContentView(R.layout.startactivity_p); //отобразить хмл портретный
}
else{
setContentView(R.layout.startactivity_l); // отобразить хмл ландскейп
}
}
I wrote the following in each xml-layout:
android:screenOrientation="landscape"
android:orientation="vertical"
and
android:screenOrientation="portrait"
android:orientation="horizontal"
respectively.
But the application still rotates. Tell me how you can fix this?
Answer:
For each of your occasions
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
and
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Doesn't turn. Actually, here's a good article .