我添加了两张图片.Default-Portrait.png和Default-Landscape.png.但每当我启动我的应用程序时,只显示纵向默认图像,而不管方向如何.
为什么会这样?
我们的应用程序可以毫无问题地支持横向模式,但是我们正在考虑强制纵向模式.
问题:是不是很糟糕?
主要问题是改变方向会在许多屏幕上产生随机崩溃.避免这些崩溃可能会让我们花更多的时间在应用程序的核心方面.当用户切换应用程序时,会发生同样的崩溃吗?
此外,是否存在面向风景的设备,我们的应用程序将变得无用?
在我的应用程序中,我目前仅支持某些活动的纵向方向,因为我认为大多数手机用户大多数时间都会使用纵向(并用一只手握住设备).
然而,在新的Honeycomb平板电脑上,用户似乎可能更频繁地使用横向,所以我想支持更多我的活动的两种方向.
我宁愿不必回去为较小的屏幕尺寸添加横向布局(一直到QVGA),所以我想知道是否有一种方法只支持xlarge屏幕类型的景观,但不是其他.
设备如何知道方向变化的功能是 - (void)viewWillLayoutSubviews和 - (void)viewDidLayoutSubviews但是,它们只是在控制器中; 现在我想知道是否有这样的函数来了解文件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 More screen.
morenavitem.rightBarButtonItem = nil;
morenavitem.title = nil;
UIImage *backgroundImage = [UIImage imageNamed:@"nav.png"];
[morenavbar setBackgroundImage:backgroundImage
forBarMetrics:UIBarMetricsDefault];
UIDeviceOrientation currentDeviceOrientation =
[[UIDevice currentDevice] orientation];
UIInterfaceOrientation currentInterfaceOrientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (UIDeviceOrientationIsLandscape(currentDeviceOrientation)||
UIDeviceOrientationIsLandscape(currentInterfaceOrientation)){
UIImage *backgroundImageLandscape = [UIImage imageNamed:@"navbar_landscape.png"];
[morenavbar setBackgroundImage:backgroundImageLandscape forBarMetrics:UIBarMetricsDefault];
}
}
Run Code Online (Sandbox Code Playgroud) 有人知道如何修复Windows Phone 8的Phonegap应用程序中的方向吗?
我希望该应用仅支持纵向方向.
我正在开发一个应用程序,我需要在其中提供不同方向的不同活动的背景图像。所以我以这种方式接近:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setLanguage();
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
// set background for landscape
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
// set background for portrait
}
}
Run Code Online (Sandbox Code Playgroud)
和
android:configChanges="locale|orientation|screenSize"
Run Code Online (Sandbox Code Playgroud)
并在onCreate()假设用户将在纵向模式下启动应用程序时,我为纵向设置了背景图像。
一切正常,因为当用户改变他们的模式时,相应的背景被设置等等。
但是,如果用户在手机处于横向模式时启动此应用程序,正如我在用户将以纵向模式启动应用程序之前假设的那样,在第一次启动时显示的纵向图像。
那么我该如何解决这个问题呢?一句话,为不同的方向设置不同的背景图像的最佳方法是什么?我在正确的轨道上吗?
我正在创建一个应用程序,我想要查看的第一个屏幕是Portrait.然后我转到下一个景观设置的活动.
我面临的问题是,如果我返回到第一个屏幕,它将被设置为横向,显然继承了前一个屏幕的方向.
有没有可能的方法将初始屏幕方向设置为已设置的纵向,但用户可以继续并在需要时将其更改为横向?
谢谢
编辑:已解决
谢谢你的建议.我已经克服了这个问题.这有点难以解释,但会尽我所能.
所以我的第一个活动有一个功能,如果手机转为横向,它将显示一个全屏显示图像.再次,如果手机是肖像,纵向视图,我有一个列表视图.
第二个活动加载一个编辑页面,让我更改该图像.
所以现在如果我按回编辑器活动.第一个活动将加载到LANDSCAPE中的列表视图中.这不是我想要的.
因此,为了解决这个问题.当第一个活动是横向时,我首先禁用了后退按钮,因此用户无法在不将手机转为横向的情况下将自己从视图中移除.
然后我移动了代码:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Show landscape picture
}
}
Run Code Online (Sandbox Code Playgroud)
在onCreate方法之前到我班级的顶部.
这已经解决了我的问题,所以现在,如果我要回到我在景观中的第一个活动,唯一可以显示的是景观视图.
我希望这清楚到足以让所有人理解:)
再一次感谢你的帮助!
如何将手机屏幕应用程序的方向锁定为肖像?
我目前config.xml正在使用此偏好:
<preference name="orientation" value="portrait"/>
然而,它没有任何区别,我仍然可以通过旋转我的移动测试设备来定位我的应用程序在两个方向.
另外,如果你知道一个活跃的phonegap/cordova社区,你可以发一个链接吗?
我有一个应用程序,我正在使用Landscape和potrait模式.我在我的每个活动中都使用了android:configChanges ="orientation | keyboardHidden".因此,当我在设备2.3上运行它时,它完全正常工作并且活动没有重新启动.但是当我在android 4.0及更高版本中打开相同的应用程序时,只要方向发生变化,活动就会重新启动.这是我的xml文件.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iconnect.collaborator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:anyDensity="true" />
<supports-screens android:smallScreens="true" />
<supports-screens android:normalScreens="true" />
<supports-screens android:largeScreens="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/cnlogomini"
android:label="CollaborateNow"
android:largeHeap="true"
android:allowBackup="true"
android:theme="@style/AppTheme" >
<activity android:name="jim.h.common.android.zxinglib.CaptureActivity"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".Register"
android:configChanges="orientation|keyboardHidden" ></activity>
<activity android:name=".ppllogincopy"
android:configChanges="orientation|keyboardHidden"></activity>
<activity android:name=".Password" …Run Code Online (Sandbox Code Playgroud) android orientation screen-orientation device-orientation android-orientation
我正在开发一个 Flutter 应用程序,我只需要在某些类中防止设备旋转,同时在其他类中保持它的工作。我现在如何在应用程序中全局禁用旋转,但如何仅在某些类中禁用它?
android ×5
orientation ×3
cordova ×2
dart ×1
flutter ×1
ios ×1
ipad ×1
iphone ×1
javascript ×1
landscape ×1
mobile ×1
objective-c ×1
portrait ×1