我正在开发一个具有以下要求的Universal项目:
我如何为iOS 8(Swift)做到这一点?
我正在尝试制作一个响应式网站,它几乎完成了,但我需要帮助。
我正在使用这个例子来了解角度:
angulo = screen.orientation || screen.mozOrientation || screen.msOrientation;
Example angulo.angle
Run Code Online (Sandbox Code Playgroud)
它返回 0,但它不适用于 Safari,仅适用于 MSF 和 Chrome。在 Safari 中,它显示:
TypeError: undefined is not an object (evaluating 'angulo.angle')
Run Code Online (Sandbox Code Playgroud)
我能做什么?
我有一个计划在Android中开发屏幕定位服务,以允许在一些手机中颠倒肖像.例如,我的是Nexus6,不能从自动旋转上下颠倒
我正在使用其他旋转控制应用程序.它缺少我需要的一个功能
我想允许来自传感器的力旋转.但是应用程序的首选方向限制为纵向或横向.如果应用程序设计为纵向模式,它可以是0或180度而不是90或270,反之亦然
我使用的所有应用程序都不能这样设置.当传感器向下对齐并且结果非常难看时,它强制横向应用程序为纵向
要做到这一点,我想我需要获得ApplicationInfo或类似的东西,并获得应用程序在其清单中设置的"android:screenOrientation"的值
可能吗?
PS.这是我想要开发的服务样本
https://play.google.com/store/apps/details?id=com.pranavpandey.rotation&hl=en
我正在研究一个应用程序,并在8.1设备(Pixel2,Nexus5x)上遇到了一个奇怪的行为,所以我写了一个小应用程序来验证这种行为.
MainActivity被锁定portrait,而模式LandscapeActivity被锁定landscape.MainActivity启动LandscapeActivityfor Result.屏幕切换portrait到landscape预期的.当LandscapeActivity完成它的传播结果MainActivity,而切换回portrait(如预期).
但有时候我会在这里遇到一些错误.之后onActivityResult在MainActivity它切换portrait到landscape切换回portrait立即.虽然我可以处理这个州,但它仍然看起来很讨厌.
为了可追溯性,我将发布所有内容以重建它.
我该怎么做才能防止它?另请注意,每次都不会发生这种情况,并且只能在8.1设备上进行测试.它似乎在8.1以下的Android设备上
编辑:
添加android:configChanges="orientation|screenSize"到我的清单@Floern建议他的答案没有成功.对平台错误的确认也是可接受的答案
表现
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LandscapeActivity"
android:screenOrientation="landscape"/>
</application>
Run Code Online (Sandbox Code Playgroud)
主要活动
public class MainActivity extends AppCompatActivity {
public static final String TAG = MainActivity.class.getSimpleName(); …Run Code Online (Sandbox Code Playgroud) android screen-orientation google-nexus google-pixel android-8.1-oreo
如何使我的Android应用程序成为横向或纵向,但没有相反的方向?
意思是说我想启用SCREEN_ORIENTATION_PORTRAIT和SCREEN_ORIENTATION_LANDSCAPE,但禁用SCREEN_ORIENTATION_REVERSE_LANDSCAPE和SCREEN_ORIENTATION_REVERSE_PORTRAIT.
谢谢
我有一个活动有多个碎片.我也使用actionbarSherlock作为我的标签,它也连接到片段.
我的问题是当我要旋转屏幕时(即纵向为横向/反之亦然),我的活动将再次被调用,以便重新启动我的活动.
我不想重新启动我的活动,只是恢复旋转之前显示的当前片段.请不要回答,android:configChanges="orientation|keyboardHidden"因为它没有解决问题,但就像一个简单的黑客.我的解决方案是OnsaveInstanceState和onRestoreInstanceState方法,但我只是不知道如何将它与我的问题一起使用.请帮帮我这个.任何回应都非常感谢.
码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tabA = actionBar.newTab().setIcon(R.drawable.about);
ActionBar.Tab tabE = actionBar.newTab().setIcon(R.drawable.faq);
ActionBar.Tab tabB = actionBar.newTab().setIcon(R.drawable.sponsors);
ActionBar.Tab tabC = actionBar.newTab().setIcon(R.drawable.map);
ActionBar.Tab tabD = actionBar.newTab().setIcon(R.drawable.destination);
Fragment aboutTab = new PhotosActivity();
Fragment sponsorTab = new SongsActivity();
Fragment mapTab = new HCCMapActivity();
Fragment questTab = new FaqActivity();
Fragment DestinationTab = new TourActivity();
tabA.setTabListener(new MyTabsListener(aboutTab));
tabB.setTabListener(new MyTabsListener(sponsorTab));
tabC.setTabListener(new MyTabsListener(mapTab));
tabD.setTabListener(new MyTabsListener(DestinationTab));
tabE.setTabListener(new MyTabsListener(questTab));
actionBar.addTab(tabD, 0, true);
actionBar.addTab(tabC, 1, false);
actionBar.addTab(tabA, …Run Code Online (Sandbox Code Playgroud) android screen-orientation android-fragments actionbarsherlock android-actionbar
我的应用程序中的所有视图控制器仅在纵向工作,除了可以是纵向或横向的视图控制器.
我有一些使用场景如下:
执行这些操作后,应用程序将保持横向方向,并且不会自动将其更改为纵向.
我使用supportedInterfaceOrientations控制视图控制器方向(我使用的是iOS 6.0).我做错了什么?当用户按下后退按钮时应用程序自动将方向更改为允许时,如何才能获得正确的行为?谢谢你的答案!
只想阻止方向,直到我的视图中加载了所有数据.所以我想到了以下代码,但它不起作用.
private class task extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
...
}
protected void onPostExecute(String result) {
...
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
protected void onPreExecute() {
...
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行这两行SENSOR并且NOSENSOR我的屏幕自动变为水平,而不理解为什么.那可能会发生?
编辑: 我将以下行检查当前方向,结果如下:
protected void onPreExecute() {
if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE) {
Log.e("TAG","LANDSCAPE");
}else{
Log.e("TAG","PORTRAIT");
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
Run Code Online (Sandbox Code Playgroud)
Logcat的结果:
LANDSCAPE
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除两行(SetRequestedOrientation),我在logcat中得到这个:
PORTRAIT
Run Code Online (Sandbox Code Playgroud) 我已经使用此代码作为@gnobal发布在/sf/answers/189047841/上,它运行良好.但我的问题是,我发现当我应用Theme.Transparent时,当我旋转手机时,活动不会进入横向模式.
主题:
<style name="Theme.Transparent" parent="android:Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutImagen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:windowContentOverlay="@null"
android:windowNoTitle="true"
tools:context=".ImagenExamen_activity" >
<!-- android:background="#CC000000" -->
<!-- android:backgroundDimEnabled="true" -->
<ImageView
android:id="@+id/imageViewImagen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
活动:
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import com.meapp.Utilities;
public class Imagen_activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imagen_examen);
Bundle b = getIntent().getExtras(); …Run Code Online (Sandbox Code Playgroud) 我有一小组大约90个用户非常重要,所以当这些商业客户中的一个或两个希望在他们的网络应用程序中更改UI时,他们通常会获得专用的开发资源.但是,对于我们来说,确切了解整个组织如何使用该应用程序非常重要,因为该组往往对其UI应该如何看起来具有强烈的个人观点,并且他们都以不同方式使用该应用程序.我在识别硬件和软键盘的使用方面遇到了最大麻烦.最理想的是,我正在寻找一个简单的答案,"使用新的Window.TabletMode == true!" 我不认为这个简单的答案存在.
window.orientation属性为肖像返回0,为横向视图返回90或-90.
结合window.innerHeight,我可以使用像......
var portrait;
$(window).on("orientationchange",function(event){
if (event.orientation == 0)
{
portrait = true;
}
else //if not, it's landscape
{
portrait = false;
}
});
Run Code Online (Sandbox Code Playgroud)
然后我将window.innerHeight结合使用的值portrait来确定宽高比是否看起来我打开了键盘.考虑到我相当狭窄的约束,这种方法确实可以全屏工作,但是如果浏览器不是全屏的呢?我确信还有很多其他理由不为此编写hacky比率计算.此外,我最大的愿望当然是使用任何浏览器和任何屏幕尺寸.
我可以处理的这些事情:我需要在加载文档时设置变量,并找出确定何时键入变得相关的方法.我可能需要检查一些浏览器功能.也许我会在有和没有硬件键盘的情况下增加计数器的输入.一旦我达到一定数量(比方说5次击键),我就会向我的数据跟踪端点发送一个POST请求,让它知道会话12345使用了软键盘(或硬键盘).之后,我将取消订阅事件处理程序.但是我工作的这部分不太受关注,因为我不认为我会陷入任何困境,但我不希望任何人花时间去美化或开发一个巨大的例子.
android ×6
ios ×2
javascript ×2
browser ×1
google-nexus ×1
google-pixel ×1
iphone ×1
keyboard ×1
objective-c ×1
safari ×1
tablet ×1