[英]orientation android
I want to add orientation on my app but I need that--> when my phone on PORTRAIT style works A activity and when I change PORTRAIT style as LANDSCAPE style A activity stops and B activity starts.How can I handle this? 我想在我的应用程序上添加方向,但是我需要->当我的PORTRAIT样式的电话可以正常工作时,并且当我将PORTRAIT样式更改为LANDSCAPE样式A活动而B活动开始时,如何处理呢? Thanks...
谢谢...
do this 做这个
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
//here call activity A
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
//here call activity B
}
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
}
if (getResources().getConfiguration().orientation ==Configuration.ORIENTATION_LANDSCAPE)
{
}
Start your Activity B
with below code - 使用以下代码启动
Activity B
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Intent a = new Intent(this, B.class);
startActivity(a);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
//do nothing
}
}
And, in your AndroidManifest.xml
file's both activity tag. 并且,在您的
AndroidManifest.xml
文件的两个活动标签中。 Just declare like below 就像下面这样声明
<activity android:name=".A"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
First check the orientation this way: 首先以这种方式检查方向:
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
and start the Activity you wanted depending on the value of orientation. 并根据方向值启动所需的活动。
then in the activity override this method: 然后在活动中覆盖此方法:
public void onConfigurationChanged(Configuration newConfig) {
//start the other activity
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.