2011-04-15 101 views
1

我在我的布局中使用了一个gestureOverlayView,用于绘制数字签名。当我绘制某个方向(如风景)然后改变方向时,问题就会出现 - overlayView刚好清除。我试过包括onConfigurationChanged();但没有效果。我也试图与onSaveInstance和onRestoreInstance以下,但它给了我无解:手势在方向改变时清除

@Override 
protected void onSaveInstanceState(Bundle outState) { 
    Gesture gesture = overlay.getGesture(); 
    outState.putParcelable("gesture", (Parcelable) gesture); 
    super.onSaveInstanceState(outState); 
} 

@Override 
protected void onRestoreInstanceState(Bundle savedInstanceState) { 
    Gesture gesture = (Gesture) savedInstanceState.getParcelable("gesture"); 
    overlay.setGesture(gesture); 
    mDoneButton.setEnabled(true); 
    super.onRestoreInstanceState(savedInstanceState); 
} 

我自己也尝试包括:

android:configChanges="fontScale|uiMode|screenLayout|navigation|touchscreen|mcc|mnc|orientation|keyboardHidden|keyboard"> 

但是,即使这是没有用的。

有没有人有这个问题的解决方案?

+0

嘿感谢您的编辑乔恩你能也帮我弄了上述回答 – 2011-04-20 04:15:18

回答

2

我想你的代码在我的应用程序和有同样的问题。 getGesture()的结果在onSaveInstanceState,onStop和onPause中为null,所以我猜测GestureOverlayView在屏幕旋转和调用这些方法之间的某处失效。

解决方法是覆盖onGesturePerformed,假设您的Activity实现了OnGesturePerformedListener,并且您在叠加层上调用addOnGesturePerformedListener(this),并保存最近的Gesture的成员实例。例如:

@Override 
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
    mCurrentGesture = gesture; 
    } 

然后在您的onSaveInstanceState中,只需获取并打包成员实例,而不是调用getGesture()。现在,当Activity重新创建时,setGesture()应该按预期工作。

+0

hey thnx ..我会尝试自己实现这个 – 2011-05-12 11:30:03

0

当方向改变时,它重新开始活动。您可以尝试限制清单文件中应用程序的方向。

机器人:screenOrientation = “肖像”

+0

?嘿,谢谢,但我不想限制方向。我想保留手势,以防方向发生变化。 – 2011-05-10 04:38:37

1

使用Android:configChanges =“fontScale | uiMode |屏幕布置|网站导航|触摸屏| MCC在清单或尝试onSavedInstance;