문제

My goal is to make an Android app that displays traditional Mongolian. However, Mongolian is displayed vertically, even though the font writes it horizontally like English. Thus, if I print it on the screen in portrait mode I have to hold the phone as if it were in landscape mode in order to read it properly (and vice versa).

I've seen a lot of questions about forcing it into one mode or another by adding a line like one the following to the AndroidManifest.xml file:

android:screenOrientation="landscape" 
android:screenOrientation="portrait" 

but I want to dynamically switch between both orientations, just opposite from what you would normally want.

If there is a better solution, then I am open to that, too. I've tried things like setting

android:rotation="90" 

in the view's xml, but it wasn't displaying correctly for even one view, let alone multiple view objects. I also saw solutions for rotating individual views with canvas, but that seemed more complex than just reversing the orientation, since everything needs to be rotated (including TextViews, Buttons, ListViews, etc.)

UPDATE: I finally chose an answer because I wasn't getting any other answers. I'm still not sure how to implement it. My plan now is just to allow users to select a fixed orientation in settings.

도움이 되었습니까?

해결책

To change orientatio, from within your activity call:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

to catch orientation event implement onConfigurationChange() and add orientation to you configration in manifest

다른 팁

final int orientation = getResources().getConfiguration().orientation; 

then, Use this where you want to switch orientation:

switch(orientation) {
   case Configuration.ORIENTATION_PORTRAIT:
       setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
       break;
   case Configuration.ORIENTATION_LANDSCAPE:
       setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
       break;                   
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top