gpt4 book ai didi

android - 方向改变时手势清除

转载 作者:搜寻专家 更新时间:2023-10-30 22:19:33 24 4
gpt4 key购买 nike

我的布局中有一个 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">

但即使这样也没有用。

有人能解决这个问题吗?

最佳答案

我在我的应用程序中尝试了您的代码,但遇到了同样的问题。在 onSaveInstanceState、onStop 和 onPause 中,getGesture() 的结果为 null,因此我猜测 GestureOverlayView 在屏幕旋转和调用这些方法之间的某处无效。

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

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

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

关于android - 方向改变时手势清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5672934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com