screen-orientation

Set the orientation to portrait from code

感情迁移 提交于 2019-12-02 02:17:41
I know I can limit the orientation from the manifest file. Like this android:screenOrientation="portrait" But is it possible to set the orientation from code ? for example setting the activity to full screen can be done both from manifest and from code this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Shailendra Singh Rajawat Activity. setRequestedOrientation(..) 来源: https://stackoverflow.com/questions/8035453/set-the-orientation-to-portrait-from-code

EXC_BAD_ACCESS when trying to get iPhone screen dimensions

允我心安 提交于 2019-12-02 01:47:18
I'm trying to make certain elements resize according to the screen dimensions when the interface orientation changes. I've read in various places (including a few answers on here) that the way to get the bounds of the screen is to use [[UIScreen] mainScreen] bounds]. So I've added this code to see how it behaves: - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { NSLog(@"view dimensions: (%@, %@)", [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height); } But when running it, as soon as I

Freeze screen orientation

纵饮孤独 提交于 2019-12-02 00:10:32
There is CheckBox with following code: CheckBox cb = (CheckBox)findViewById(R.id.freezer); cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); } } }); So, when i check it, screen is rotated to default system orientation (landscape for my tablet). I need to freeze CURRENT orientation. If you turned device to portrait and

How can I know the orientation changed in AppDelegate

为君一笑 提交于 2019-12-01 22:34:09
问题 The function of how the device know the changement of orientation is -(void)viewWillLayoutSubviews and -(void)viewDidLayoutSubviews But, they are just in the controllers; Now I want to know is there any functions like these to know the changement of orientation in the file AppDelegate.m - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { UINavigationBar *morenavbar =

How can I know the orientation changed in AppDelegate

我们两清 提交于 2019-12-01 21:29:53
The function of how the device know the changement of orientation is -(void)viewWillLayoutSubviews and -(void)viewDidLayoutSubviews But, they are just in the controllers; Now I want to know is there any functions like these to know the changement of orientation in the file AppDelegate.m - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { UINavigationBar *morenavbar = navigationController.navigationBar; UINavigationItem *morenavitem = morenavbar.topItem; //We don't need Edit button in

Unity Cardboard Orientation Landscape Right Upside Down

可紊 提交于 2019-12-01 20:26:30
Hi I have a Unity app which uses google Cardboard SDK to enable stereoscopic view so I will have a VR enabled app. My app runs perfectly fine. But there is a problem if I set the player settings orientation to be auto orientation with only landscape left and landscape right allowed. When it is in landscape left, everything works as per normal but when it is in landscape right the cardboard view will turn 180 degrees (settings button moved to bottom of screen) but my unity objects does not. Thus I have an upside-down objects. Any method to fix this? Thanks. It appears the native code that the

How to implement UIViewController rotation in response to orientation changes?

荒凉一梦 提交于 2019-12-01 16:29:24
My app has about 10 different UIViewControllers, just one of which I want to switch to landscape mode if the device is rotated. (All the rest, I want to keep in portrait.) In order to implement rotation on that one view, I needed to implement its controller's 'shouldAutorotate' method and return YES. Since this view is accessed via a navigation controller, I also needed to create a subclass of UINavigationController that implements 'shouldAutorotate' and return YES. This solution works, but too well. I find that all of the UIViewControllers I push onto my subclass of UINavigationController

How to implement UIViewController rotation in response to orientation changes?

自闭症网瘾萝莉.ら 提交于 2019-12-01 15:59:13
问题 My app has about 10 different UIViewControllers, just one of which I want to switch to landscape mode if the device is rotated. (All the rest, I want to keep in portrait.) In order to implement rotation on that one view, I needed to implement its controller's 'shouldAutorotate' method and return YES. Since this view is accessed via a navigation controller, I also needed to create a subclass of UINavigationController that implements 'shouldAutorotate' and return YES. This solution works, but

Fragments restore state on orientation changed

无人久伴 提交于 2019-12-01 15:10:28
问题 I have to implement "standart" fragments navigation in my app (please see link). The issue is when device is in portrait mode, there should be shown only 1 fragment, and when it is rotated to landscape mode, 2 fragments should be shown. I tried to do this 2 different ways: 1) I use only 1 activity with different portrait and landscape layouts. Portrait layout xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android

Disable screen rotating on Android [duplicate]

半世苍凉 提交于 2019-12-01 10:36:00
This question already has an answer here: How do I disable orientation change on Android? 12 answers When I press a button, I would like to disable screen rotation on all my activities . How can I do that? BTW, the phone can be located in landscape or portrait position when the user click the button. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mdma You can change your AndroidManifest.xml to <activity android:name="MainActivity" android:configChanges="orientation"> Which informs the OS that you will