在Android中检查设备方向
我想在不更改当前活动方向的情况下,根据设备的方向更改创建新活动。有没有办法做到这一点 其他信息: 我的总应用程序默认方向是Portrate。当设备处于横向时,我必须打开第二个活动。但第一个活动应该是Portrate在Android中检查设备方向,android,orientation,Android,Orientation,我想在不更改当前活动方向的情况下,根据设备的方向更改创建新活动。有没有办法做到这一点 其他信息: 我的总应用程序默认方向是Portrate。当设备处于横向时,我必须打开第二个活动。但第一个活动应该是Portrate .您可以在您的AndroidMenifest.xml中使用android:screenOrientStation=“Landscape/Portrate”来执行特定的活动。这样,活动的其余部分将保留在默认视图中,并且当您确定尺寸时,特定的视图中将强制显示特定的活动 希望这对您有所帮助
.您可以在您的
AndroidMenifest.xml
中使用android:screenOrientStation=“Landscape/Portrate”
来执行特定的活动。这样,活动的其余部分将保留在默认视图中,并且当您确定尺寸时,特定的视图中将强制显示特定的活动
希望这对您有所帮助。您可以在您的
AndroidMenifest.xml
中使用android:screenOrientStation=“Landscape/Portrate”
来进行特定活动。这样,活动的其余部分将保留在默认视图中,并且当您测量尺寸时,特定视图中将强制显示特定活动
希望这对你有帮助。当然可以。您只需在清单中声明您的第一个活动将处理方向更改。然后添加一个onConfigurationChanged函数来启动第二个活动。当然可以。您只需在清单中声明您的第一个活动将处理方向更改。然后添加一个OnConfiguration Changed函数以启动第二个活动。写入Menifest 第一次活动
<activity android:name="firstActivity" android:screenOrientation="portrait"></activity>
<activity android:name="secondActivity" android:screenOrientation="landscape"></activity>
第二项活动
<activity android:name="firstActivity" android:screenOrientation="portrait"></activity>
<activity android:name="secondActivity" android:screenOrientation="landscape"></activity>
在Menifest中写入
第一次活动
<activity android:name="firstActivity" android:screenOrientation="portrait"></activity>
<activity android:name="secondActivity" android:screenOrientation="landscape"></activity>
第二项活动
<activity android:name="firstActivity" android:screenOrientation="portrait"></activity>
<activity android:name="secondActivity" android:screenOrientation="landscape"></activity>
您还可以通过编程方式检测活动的当前方向,并在设备处于横向模式时运行第二个活动的意图。以下是实现此功能的代码:
WindowManager wm = getWindowManager();
Display d = wm.getDefaultDisplay();
if(d.getWidth() > d.getHeight())
{
// landscape mode
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
}
您还可以通过编程方式检测活动的当前方向,并在设备处于横向模式时运行第二个活动的意图。以下是实现此功能的代码:
WindowManager wm = getWindowManager();
Display d = wm.getDefaultDisplay();
if(d.getWidth() > d.getHeight())
{
// landscape mode
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
}
谢谢大家的帮助。最后,我使用
SensorEventListener
完成了这项工作
OnCreate()
听众
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);
}
}
private SensorEventListener mySensorEventListener=new SensorEventListener(){
精度更改时的公共无效(传感器,int精度){
}
传感器更改时的公共无效(传感器事件){
//磁北方向与磁北方向的夹角
//0=北,90=东,180=南,270=西
浮动方位角=事件值[1];
//compassView.updateData(方位角);
如果((方位角<100&&方位角>60)
||(方位角>-100和方位角<-60)){
如果(东距!=0){
if(!Modules.LoanType.equalsIgnoreCase(“Ballcash”)){
Intent in=新Intent(Buyeroutput.this,Esteregg.class);
星触觉(in);
东距=0;
}
}
}否则{
EasterVal=1;
}
}
};
受保护的空onDestroy(){
super.ondestory();
如果(传感器!=null){
sensorManager.UnregistereListener(mySensorEventListener);
}
}
谢谢大家的帮助。最后,我使用SensorEventListener
完成了这项工作
OnCreate()
听众
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);
}
}
private SensorEventListener mySensorEventListener=new SensorEventListener(){
精度更改时的公共无效(传感器,int精度){
}
传感器更改时的公共无效(传感器事件){
//磁北方向与磁北方向的夹角
//0=北,90=东,180=南,270=西
浮动方位角=事件值[1];
//compassView.updateData(方位角);
如果((方位角<100&&方位角>60)
||(方位角>-100和方位角<-60)){
如果(东距!=0){
if(!Modules.LoanType.equalsIgnoreCase(“Ballcash”)){
Intent in=新Intent(Buyeroutput.this,Esteregg.class);
星触觉(in);
东距=0;
}
}
}否则{
EasterVal=1;
}
}
};
受保护的空onDestroy(){
super.ondestory();
如果(传感器!=null){
sensorManager.UnregistereListener(mySensorEventListener);
}
}
在AndroidMenifest.xml中为活动设置默认方向后,我无法识别活动的屏幕方向。无需重新确定方向,因为您的Perticular活动处于横向模式或portrate模式,因为您的menifest文件中有尺寸。请参阅您需要做的只是使用ScreenOrientation=“横向”
您希望在scape.Ex中显示的活动的属性
对于您希望在横向中进行的活动,请这样做。对不起。一旦我将第一个活动(在方向改变时必须打开第二个活动)设置为portrate。getResources().getConfiguration().orientation无法识别方向更改。您不需要查找方向。只需使用ScreenOrientation属性,在AndroidMenifest.xml中为活动设置默认方向后,它将自动以横向模式启动活动,我无法识别活动的屏幕方向。无需重新确定方向,因为您的Perticular活动处于横向模式或portrate模式,因为您的menifest文件中有尺寸。请参阅您需要做的只是使用ScreenOrientation=“横向”
您希望在scape.Ex中显示的活动的属性
对于您希望在横向中进行的活动,请这样做。对不起。一旦我将第一个活动(在方向改变时必须打开第二个活动)设置为portrate。getResources().getConfiguration().orientation不识别t