[英]Landscape and Portrait view in android tablet
I am working on android. 我正在使用android。 I will tried the following code to prevent the application to restart when the tab or phone is rotated. 我将尝试使用以下代码来防止应用程序在旋转标签页或手机时重新启动。 It is working but it does not give the landscape and portrait view correctly. 它正在工作,但是不能正确显示风景和肖像。
android:configChanges="keyboardHidden|orientation"
Actually, 其实,
android:configChanges="orientation"
android:screenOrientation="landscape"
attributes of an Activity
declaration in the Manifest doesn't prevent the activity from being recreated whenever orientation changes, it prevents the platform from doing anything to the orientation by default and keeps it by default eg landscape. 清单中Activity
声明的属性不会阻止在方向更改时重新创建活动 ,它会阻止平台默认情况下对方向执行任何操作,并默认情况下将其保留,例如,横向。
You can override 您可以覆盖
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.newLayout);
}
to force recreation of the activity. 迫使活动重新进行。
If you have 2 layouts (portrait and landscape) and the order seems to be reversed on the tablet then switch to using getRotation
instead of deprecated getOrientation
. 如果您有2种布局(纵向和横向),并且在平板电脑上的顺序似乎相反,则切换为使用getRotation
而不是不赞成使用的getOrientation
。 Something like this 像这样
private void setLayout() {
// Get display for detecting the phone orientation
final Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if (display.getRotation() == Surface.ROTATION_0 || display.getRotation() == Surface.ROTATION_180) {
setContentView(R.layout.home);
} else {
setContentView(R.layout.home_l);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.