问题描述
你好朋友,
我正在使用FlashBuilder 4.6开发Android应用.
在应用程序中,需要在设备方向改变时设置一些值.即当屏幕/设备方向从横向"更改为纵向"或反之时,设置值.
尽管最初我的应用程序具有 LandScape 方向.这项要求是针对特定的观点.
我希望每次屏幕/设备方向更改时都必须在此处设置值.
我没有得到理想的结果.
请指导我,并告诉我代码是否错误或如何实现.
Hello friends,
I''m working with FlashBuilder 4.6 to develop Android app.
In the application there is a requirement of setting some values when device orientation changes. i.e. setting the values when the screen/device orientation changes from Landscape to Portrait and vice-verse.
Although Initially my application has LandScape orientation. And this requirement is on specific view.
I want every time when the screen/device orientation changes the values must be set there.
I am not getting the desired result.
Please guide me and tell me if I am at wrong in code or how can i achieve this.
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="{data}"
xmlns:mx="library://ns.adobe.com/flex/mx"
viewActivate="view1_viewActivateHandler(event)"
creationComplete="view1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if(Accelerometer.isSupported)
{
accl = new Accelerometer();
accl.addEventListener(AccelerometerEvent.UPDATE,update); //accl.addEventListener(AccelerometerEvent.UPDATE,adjustImage);
}
}
private function update(event:AccelerometerEvent):void
{
this.stage.autoOrients = true;
//in the below line I am attaching StageOrienationEvent that will adjust the
//values.
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,adjust);
}
private function adjust(event:StageOrientationEvent):void
{
if(event.afterOrientation == StageOrientation.ROTATED_LEFT)
{
testVal.text ="After OR is LEFT";
}
else if(event.afterOrientation == StageOrientation.ROTATED_RIGHT)
{
testVal.text ="After OR is RIGHT";
}
else if(StageAspectRatio.LANDSCAPE)
{
testVal.text ="StageAspectRatio is Landscape";
}
else if(StageAspectRatio.PORTRAIT)
{
testVal.text="StageAspectRatio is Portrait";
}
}
</fx:Script>
谢谢.
Thanks.
推荐答案
protected function update(event:AccelerometerEvent):void
{
this.stage.autoOrients = true;
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING,adjust);
}
protected function adjust(event:StageOrientationEvent):void
{
switch(event.afterOrientation)
{
case StageOrientation.DEFAULT:
//Do Something here. The Portrait Position.
break;
case StageOrienatation.ROTATED_LEFT:
//Do Something here when you rotate your phone portrait to left side.
break;
case StageOrienatation.ROTATED_RIGHT:
//Do something here when you rotate your phone portrait to right side.
break;
}
}
非常感谢所有查看此问题并尝试解决问题的人.
快乐编程:)
Many thanks to all who viewed this question and try put their efforts for solution.
Happy Programming :)
这篇关于Flash Builder 4.6移动方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!