屏幕旋转与方向更改相结合

时间:2012-07-17 19:34:55

标签: android orientation screen-orientation android-sensors tilt-sensor

我想要建立什么;

App始终处于横向模式(左侧手机顶部!)。

当用户翻转手机时(在Y轴上,因此用户正在查看它的背面,屏幕位于坐在桌子另一端的人的面前),该指示应更改为“逆向风景”。在这种情况下,正在显示的TextView对于看屏幕的人来说是正确的。

然后,当用户翻回手机时,方向应该变回横向。

但是...(这就是捕捉......)当用户将手机转过X轴时(顺便看一下屏幕,顺时针转动它),没有任何事情发生。(在游戏中,这个会作弊)

我尝试使用onSensorChanged,但它的行为与我描述的不同。有什么想法吗?日Thnx

public void onSensorChanged(SensorEvent event) {  

                TextView tv = (TextView) findViewById(R.id.TextView01);
                tv.setText("0 : " + event.values[0] + "1 : " + event.values[1] + " -- 2 : " + event.values[2]);

                if (event.values[1] < -6 || event.values[1] > 6) {
                    playfair();
                    return;
                } else {if (event.values[1] > -6 || event.values[1] < 6){cheat = false;}}
                if (event.values[0] < -8.5) {
                    if (state == PRE_ROUND)
                    startround();                                               
                } else {
                    if (state == SHOWING_OBJECT){
                        flipper.setInAnimation(inFromBottomAnimation(1));
                        flipper.setOutAnimation(outToTopAnimation(1));
                        flipper.setDisplayedChild(1);

                        state = PRE_ROUND;  
                    }

                }                   
            }

0 个答案:

没有答案