我们如何将仿真器屏幕方向更改为横向或纵向?
我希望我的Android应用程序只能以纵向模式运行?我怎样才能做到这一点?
我已经成功实现onRetainNonConfigurationInstance()了我的主要功能,Activity以保存和恢复屏幕方向更改中的某些关键组件.
但看起来,当方向发生变化时,我的自定义视图将从头开始重新创建.这是有道理的,虽然在我的情况下它很不方便,因为所讨论的自定义视图是X/Y图,并且绘制的点存储在自定义视图中.
是否有一种狡猾的方法来实现类似于onRetainNonConfigurationInstance()自定义视图的东西,或者我是否需要在自定义视图中实现允许我获取并设置其"状态"的方法?
我希望平板电脑能够以纵向和横向(sw600dp或更高)显示,但手机仅限于纵向.我找不到有条件选择方向的方法.有什么建议?
我的主要活动有一些代码,可以进行一些不应该被中断的数据库更改.我正在另一个线程中进行繁重的工作,并使用我设置为不可取消的进度对话框.但是,我注意到如果我旋转手机,它会重新启动对正在运行的进程非常不好的活动,并且我会收到强制关闭.
我想要做的是以编程方式禁用屏幕方向更改,直到我的进程完成,此时方向更改已启用.
我认为这是可实现的,因为屏幕旋转行为可以达到应用程序级别.
安卓工作室 3.6。
我希望我的应用程序始终处于portrait模式。所以在我的AndroidMainfest.xml:
<activity
android:name=".activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我运行该应用程序并SplashActivity以portrait模式显示。好的。但是编辑器显示以下错误:
Expecting android:screenOrientation="unspecified"
Run Code Online (Sandbox Code Playgroud)
为什么?
我想找出一个装置的详细取向,优选的一个SCREEN_ORIENTATION_LANDSCAPE,SCREEN_ORIENTATION_PORTRAIT,SCREEN_ORIENTATION_REVERSE_LANDSCAPE,SCREEN_ORIENTATION_REVERSE_PORTRAIT从ActivityInfo或等同物.
StackOverflow中的一些答案包括在内
getWindowManager().getDefaultDisplay().getRotation()
Run Code Online (Sandbox Code Playgroud)
但这并没有真正告诉我该设备是处于纵向还是横向模式,只是它是如何根据其自然位置转动的 - 而这反过来可以是风景或肖像.
getResources().getConfiguration().orientation
Run Code Online (Sandbox Code Playgroud)
返回以下三种:ORIENTATION_LANDSCAPE,ORIENTATION_PORTRAIT,ORIENTATION_SQUARE,然后并没有真正告诉我哪种方式手机处于开机状态(无论是上下颠倒或两侧的它的转向).
我知道我可以结合使用后者DisplayMetrics来找出设备的自然方向,但是真的没有更好的方法吗?
我想让我的应用程序仅在横向模式下工作,但无法使其工作.我已经给出了screenOrientation = "landscape"即使第一页将处于横向模式,其他活动将是纵向的.
XML文件
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name"
android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".IntroHome"
android:label="@string/app_name"
android:screenOrientation="landscape">
</activity>
<activity android:name=".ObjectivesPage"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
<activity android:name=".MenuPage"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
JAVA CLASS
public class ObjectivesPage extends Activity{
ImageButton imgButton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.objectivespage);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
imgButton = (ImageButton)findViewById(R.id.buttonCloseNGo);
imgButton.setOnClickListener(onClickCloseNGo);
}
private OnClickListener onClickCloseNGo = new OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(ObjectivesPage.this,MenuPage.class);
startActivity(intent); …Run Code Online (Sandbox Code Playgroud) 我在这里使用Twitter Bootstrap构建了一个响应式站点:http://zarin.me/cce/
响应式设计在iPad和iPhone上运行良好,但是当我将设备从纵向翻转到横向时,网站会放大而不是适应屏幕(捏屏幕工作).
我错过了什么?这是一个视口问题吗?这是我在我的唯一视口代码:
<meta content="width=device-width, initial-scale=1.0" name="viewport">
Run Code Online (Sandbox Code Playgroud)
提前致谢!
viewport orientation screen-orientation device-orientation responsive-design