I making an app both for phones and galaxy tab.
I want to be only portrait mode on phones, and portrait and landscape as well in tabs.
So far i got this code snippet:
public void onCreate(Bundle savedInstanceState)
{
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
if(!(width>=800 && height>=1280))
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
//... more code below
So i just check the screen size and if it is the tablet's 800x1280, i do nothing and orientation change is active. If it is not 800x1280 i do:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
I thought it will be work fine, but for some random bug, it is not working every time..
Lets say for about ten times, the orientation just changes to landscape to a second on phones then it changes back to portrait. So a little buggy a little wrong.
Is it another better way to do this?
you can set to screenOrientation in mainfest
<activity
android:name=".Dis"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
Related
How to develop app for both device orientation(portrait and landscape) in flutter. When I rotate my device in landscape, app size will adjust on landscape. If I rotate my device in portrait, app size will adjust on portrait.
The answer is simple called as "responsive design", please have a look to one of the best post about the same subject ;
https://medium.com/flutter-community/developing-for-multiple-screen-sizes-and-orientations-in-flutter-fragments-in-flutter-a4c51b849434
and also from the original source from Flutter documentation ;
https://flutter.dev/docs/development/ui/layout/responsive
Hope this works
you can develop two widgets for each orientation each one has different sizes of text, padding.... using MediaQuery.of(context).orientation to get the current orientation or you can use Layout Builder.
Otherwise, you can lock your app to a specific orientation:
import 'package:flutter/services.dart';
main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(MyHomePage());
}
As per the title, I have an AR game embedded in the flutter app that I want to run in landscape mode.
I tried using this code:
#override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
And it did work to set the screen orientation to landscape, but the problem is when the screen rotation is turned off in my phone settings, the background in AR mode starts showing the upside-down view from the camera, which looks a bit weird from the user experience perspective.
Does anybody know how to fix this?
I'm developing a game that runs on both mobile phones and tablets.
Currently I'm using only the Portrait orientation for all devices but the portrait orientation looks better on phones meanwhile landscape orientation looks better on tablets.
I set "Portrait" option in the Unity's Player Settings > Resolution and Presentation > Default Orientation but I would like to provide a landscape layout for tablets (without affecting phones).
How I can I do that? Is there any why to programmatically set the Screen orientation when the application starts?
You can try Screen.Orientation
In the Start (or Awake) method of a MonoBehaviour that is added to the stage call:
Screen.Orientation = ScreenOrientation.LandscapeRight
Now you just need to check if the device is tablet or phone, I don't know any way out of the box to do this, but you can check the aspect ratio and base your decision on this.
You can check the aspect ratio by getting Screen.width and Screen.height.
I'm using cordova 2.6 to make an iPhone application in Landscape mode only.
I've a problem with my splashscreen, when I launch app I see the good one during view seconds, then it rotate automatically before loading index page.
All params in plist, xcode and xml are on landscape mode, splashscreen has good size and all works fine on iPad. I know there is no landscape splashscreen for iPhone, I just want it still in portrait, don't rotate after view seconds.
As I can see problem is due to the splashscreen plugin of Cordova who create a view in the bad orientation after display the good splashscreen.
Thanks for your help
There is a bug in CordovaLib\Classes\CDVSplashScreen.m where it only switches out the images on an iPad for Landscape vs Portrait.
if you remove the line
} else if (CDV_IsIPad()) {
and the corresponding } then landscape will work across devices. You will need to ensure that your Resources\splash folder has the following files in it:
iPad:
Default-Portrait~ipad.png (768x1004px)
Default-Landscape~ipad.png (1024x748px)
iPad #2x:
Default-Portrait#2x~ipad.png (1536x2008px)
Default-Landscape#2x~ipad.png (2048x1496px)
iPhone:
Default-Portrait~iphone.png (320x480px)
Default-Landscape~iphone.png (480x320px)
iPhone #2x:
Default-Portrait#2x~iphone.png (640x960px)
Default-Landscape#2x~iphone.png (960x640px)
iPhone 5 #2x:
Default-568h-Portrait#2x~iphone.png (640x1136px)
Default-568h-Landscape#2x~iphone.png (1136x640px)
Hope that helps
I am building an app with Titanium, where I load a big remote xml file on startup. It shows the usual Default.png splash screen, and then gets to the window, where it says that it's loading. But what I want to do, is to make the splash screen stick until the xml is fully loaded.
Now my approach for this is quite simple, I create an imageView at the start, with the Default.png as the image like so:
var startupView =Titanium.UI.createImageView({
image: 'iphone/Default-Portrait.png',
opacity:1,
zIndex:2
});
and once the xhr.onload function is triggered (meaning the xml file is fully loaded), I fade out this startup view by doing:
var startupAnimation = Titanium.UI.createAnimation({
curve:Ti.UI.ANIMATION_CURVE_EASE_OUT,
opacity:0,
delay: 0,
duration:300
});
startupView.animate(startupAnimation);
This works fine and all, but the problem I have is, that there are different splash screen sizes for different platforms. And so far the app I am creating works well on both platforms. On the ipad the screen is obviously bigger, on the iphone 4, the retina display is also bigger compared to iphone 3gs etc. Therefor I need to come up with something to make this code work nice everywhere.
I tried to check with if (Titanium.Platform.osname == "iphone") { and load the smaller size splash screen for the iphone into the imageview, but somehow it's not the same as the "real" splash screen underneath it. Because of this, the user sees that the initial splash screen and the faked splash screen is shifting. It seems like the default splash screen loaded by titanium is not the same as Default.png, but it's the Default-Portrait.png (which should only be used for the ipad)
I have no idea whether this all is clear, and whether someone here can think with me, but any ideas would be greatly appreciated.
I have done the same thing with a Titanium iPad app. I found that I needed to create my own 'Splash Screen' image without the top 20px where the status bar would be. Because titanium apps can start full screen, the Default-Portrait.png assumes it could be full screen. When you add Default-Portrait.png view in a non-fullscreen app, it shifts it down 20px and you get that 'shifting' effect to the user.
Since you are running on iPhone and iPad, you will probably need to create new splash screens for iPad and iPhone. I would think that you could use the iPhone 4 'fake' image for non retina displays as well and let titanium handle the resizing.