我想在设备的方向更改上创建新活动,而不更改当前的活动方向。有没有办法做到这一点?在Android中检查设备方向
附加信息:
我总应用默认的方向是Portrate。当设备处于横向时,我必须打开第二个活动。但第一项活动应在Portrate 。
我想在设备的方向更改上创建新活动,而不更改当前的活动方向。有没有办法做到这一点?在Android中检查设备方向
附加信息:
我总应用默认的方向是Portrate。当设备处于横向时,我必须打开第二个活动。但第一项活动应在Portrate 。
谢谢大家的帮助。最后,我通过使用SensorEventListener
来完成此操作。
的OnCreate()
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
监听
private SensorEventListener mySensorEventListener = new SensorEventListener() {
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
// angle between the magnetic north directio
// 0=North, 90=East, 180=South, 270=West
float azimuth = event.values[1];
// compassView.updateData(azimuth);
if ((azimuth < 100 && azimuth > 60)
|| (azimuth > -100 && azimuth < -60)) {
if (EasterVal != 0) {
if (!Modules.LoanType.equalsIgnoreCase("Ballcash")) {
Intent in = new Intent(Buyeroutput.this, Esteregg.class);
startActivity(in);
EasterVal = 0;
}
}
} else {
EasterVal = 1;
}
}
};
protected void onDestroy() {
super.onDestroy();
if (sensor != null) {
sensorManager.unregisterListener(mySensorEventListener);
}
}
您可以在您的AndroidMenifest.xml
中使用android:screenOrienttation="Landscape/Portrate"
进行相关活动。因此,其余活动将保留在默认视图中,并且强化活动将强制在您的维度中显示在特定视图中。
希望这对你有所帮助。
当然你可以。您只需在清单中声明您的第一个活动将处理方向更改。然后添加一个onConfigurationChanged函数来开始你的第二个活动。
我用onConfigurationChanged。但是我必须检查方向而不改变第一个活动的方向。 – Sniper
写在Menifest
的第一个活动
<activity android:name="firstActivity" android:screenOrientation="portrait"></activity>
为第二活动
<activity android:name="secondActivity" android:screenOrientation="landscape"></activity>
一旦我将第一个活动(它必须在方向更改时打开第二个活动)设置为portrate。 getResources()。getConfiguration()。orientation不识别方向更改。 – Sniper
呵呵k我们也可以设置运行时setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); –
您也可以以编程方式检测到您当前的活动方向和运行的意图到您的第二个活动,只要您的设备处于横向模式。这里是一个代码来完成它:
WindowManager wm = getWindowManager();
Display d = wm.getDefaultDisplay();
if(d.getWidth() > d.getHeight())
{
// landscape mode
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
}
设置默认方位AndroidMenifest.xml的活动结束后,我无法识别该活动的屏幕方向。 – Sniper
无需重新定位方向,因为您的审稿人活动处于横向或端口模式,因为您在清单文件中有内容。 – Akshay
看到你所要做的只是使用'screenOrientiation =“Landscape”'属性为你想在landscape.Ex中进行的活动。 ''就像你想要的风景那样。 –
Akshay