我正在构建一个基于倾斜的游戏,并希望将方向锁定为 1 个特定的横向方向(iOS 上的 UIInterfaceOrientationLandscapeRight)。但是,如果您将 cordova Orientation 首选项设置为landscape,它仍然可以旋转 180 度到任一横向模式,这对我来说是不可接受的。这是cordova的缺点吗?我需要这个,而且本地做起来很简单,所以似乎应该有一个简单的方法来做到这一点。
我知道cordova-plugin-screen-orientation,但它只有在你的 javascript 开始运行后才会执行操作,这对于你的启动屏幕来说已经太晚了。
当我按下按钮时,我想在我的所有活动中禁用屏幕旋转.我怎样才能做到这一点?
顺便说一句,当用户点击按钮时,手机可以位于横向或纵向位置.
如果在发生方向更改时触发了onChange函数,如何在onChange中设置将更新jquery选择器的值.例如:
$(document).ready(function(){
var onChanged = function() {
if(window.orientation == 90 || window.orientation == -90){
image = '<img src="images/land_100.png">';
}else{
image = '<img src="images/port_100.png">';
}
}
$(window).bind(orientationEvent, onChanged).bind('load', onChanged);
$('#bgImage').html(image); //won't update image
});
Run Code Online (Sandbox Code Playgroud) 使用已android 2.1 & 2.2安装的手机,使用最简单的hello world应用程序并将 android:theme ="@ android:style/Theme.Translucent"添加到android清单中的活动以使应用程序透明,该应用程序坚持为肖像仅旋转电话时不会旋转到横向.
拿出线,应用程序旋转正常.这可以通过override of onConfigurationChanged在该例程中添加和放置断点来验证.Brk在未应用半透明时命中,在添加半透明时不会.
但是,使用andr 2.2使用三星星系标签,即使使用半透明,旋转也能正常工作.任何人对此都有任何想法?
我知道我可以限制清单文件的方向.像这样
android:screenOrientation="portrait"
Run Code Online (Sandbox Code Playgroud)
但是可以从代码中设置方向吗?
例如,可以从清单和代码中将活动设置为全屏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
在我的代码中,我创建了一个卡类; 我稍后在gridview中展示了一堆卡片.在屏幕方向改变时,我正在丢失所有卡片; 在我之前的问题中,我指出了正确的方向.
现在,我在Android文档中找到的内容以及StackO中的内容就是这样
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt(...);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
some_int_var = savedInstanceState.getInt(...);
super.onRestoreInstanceState(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)
}
现在,我这样做好,因为Bundle对象有几个方法,如putString,Char等.原语加上字符串.但我的卡怎么样?它们是向量中的Card对象,因此我不能使用任何这些方法.
如何在不使用onRetainNonConfigurationInstance的情况下恢复该向量,也不会阻止活动重置?在Android文档中,如果要重新启动重型数据,建议执行此操作,但这不是我的情况.
我的应用程序应该首先显示图像,当按下按钮时,另一个图像显示在图像视图中.但是,当旋转屏幕时,imageView会显示旧图像.我该怎么办呢?(bits是在创建时加载到imageView的Bitmap)
我的代码如下:
RGBToBitmap(rgb.getWindow(), bits); //this loads a new image into bits
imageView.setImageBitmap(bits);
Run Code Online (Sandbox Code Playgroud) 当我旋转设备并且如果我选择了除第一个或最后一个之外的某个选项卡,它会向我显示选项卡的错误位置.
但当我做一个小触摸手势时,它会更新自己.你知道怎么解决这个问题.
我的phonegap应用应该以纵向方式运行.只能在横向模式下运行一个页面(index.html).然后我找到了这个插件,但对我不起作用.
cordova plugin add net.yoik.cordova.plugins.screenorientation
在config.xml中:
<preference name="orientation" value="portrait" />
index.html的:
<html>
<head>
<title>App</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script>
var so = cordova.plugins.screenorientation;
so.setOrientation(so.Orientation.LANDSCAPE);
</script>
Run Code Online (Sandbox Code Playgroud)
对于android,应用程序返回错误App has stopped.
对于iPhone,没有任何事情发生.
在我的Android应用中,我使用不同的Android资源目录来支持多种屏幕尺寸和方向。所以在res我里面有一个layout文件夹,一个layout-land文件夹,一个layout-large文件夹,一个layout-large-land文件夹等等。
在我尝试将我的应用安装到具有18:9显示屏而不是显示屏的较新手机中之前,这种方法对我来说非常有效16:9。
该电话从layout和layout-land文件夹中提取资源,这意味着它将被注册为“常规”屏幕。
此外,如果我尝试使用以下代码获取此手机的屏幕尺寸,
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
Toast.makeText(this, "Extra Large Screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large Screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
Toast.makeText(this, "Normal Screen", Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
Toast.makeText(this, "Small Screen", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(this, "Screen size is neither xlarge, large, normal or small", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
然后再次将其注册为正常屏幕。但是具有16:9显示屏的手机也是如此。不用说,这在这两款手机上的应用外观上产生了微小但明显的差异。
所以我的问题是,有没有办法区分这两种显示?
注意:我知道有一些解决方法,例如dp …
android screen-orientation android-layout screen-size android-resources