Programmatically lock into portrait mode for certain operations
Try this:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//Do your operation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Workaround to lock portrait orientation in a relative layout?
You can define orinetation in AndroidManifest.xml
<activity android:name=".NameOfTheActivity"
android:screenOrientation="portrait"/>
Flutter: How to set and lock screen orientation on-demand
First import the services package:
import 'package:flutter/services.dart';
This will give you access to the SystemChrome
class, which "Controls specific aspects of the operating system's graphical interface and how it interacts with the application."
When you load the Widget, do something like this:
@override
void initState(){
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
then when I leave the page, put it back to normal like this:
@override
dispose(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}
How do I lock the sceen from rotating in a steroids.js - AppGyver mobile app
AppGyver employee here – I just wrote a quick device orientation guide about the issue. Hope this answers your question!
Method to programmatically switch between Landscape-Portrait for a single View on Android?
No: orientation is currently handled at the Activity level, not the View level. If you had a completely custom View you could CHOOSE to draw it in landscape yourself (landscape simply being longer side as the horizontal, shorter as the vertical) but with the MapView you don't get that option.
How to set portrait view for android application
To do it pro-grammatically in every activity.
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
How do I make it only landscape for tablets and only portrait for phones?
Here is my suggestion:
First try to determine the type of device using screen dimensions. You could refer to this post.
On the second step you can change the screen orientation using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
. There is another post here.
Related Topics
Android: Share Session Between Webview and Httpclient
Crop Square Image to Circle - Programmatically
Commitallowingstateloss() in Fragment Activities
Android: Converting Color Image to Grayscale
How to Set Android Tablayout in The Bottom of The Screen
How to Find Out Carrier's Name in Android
View Pager + Imageview +Pinch Zoom + Rotation
Should I Use Getapplicationcontext or Activity.This in a Long Running Asynctask
Error: Error Parsing Xml: Not Well-Formed (Invalid Token) ...
How to Deal with Deprecated Classes in Android to Keep Compatibility
Supporting Amazon and Android Market (Google Play) Links Inside Application
How to Enable Autostart Option for My App in Xiaomi Phone Security App Programmatically in Android
Android Getting Exact Scroll Position in Listview
Httpurlconnection.Openconnection Fails Second Time
Inconsistency Detected in Recyclerview, How to Change Contents of Recyclerview While Scrolling