方向改变时手势会清除

发布于 2024-11-02 00:33:18 字数 919 浏览 4 评论 0原文

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

但即使这样也没有用。

有人有解决这个问题的办法吗?

I have a gestureOverlayView in my layout which I am using for drawing digital Signature. The problem arises when I draw in a certain orientation (say landscape) and then change the orientation - the overlayView just clears. I have tried including onConfigurationChanged();but no effect. I have also attempted the following with onSaveInstance and onRestoreInstance, but it gives me no solution:

@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);
}

I have also tried including:

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

But even this is of no use.

Does anyone have a solution for this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

就像说晚安 2024-11-09 00:33:18

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

解决方法是重写 onGesturePerformed,假设您的 Activity 实现 OnGesturePerformedListener 并且您在叠加层上调用 addOnGesturePerformedListener(this),并保存最近手势的成员实例。类似于:

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

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

I tried your code in my application and had the same issue. The result of getGesture() is null within onSaveInstanceState, onStop, and onPause, so I'm guessing that the GestureOverlayView is invalidated somewhere between the screen rotation and the calling of those methods.

A workaround is to override onGesturePerformed, assuming your Activity implements OnGesturePerformedListener and you call addOnGesturePerformedListener(this) on your overlay, and save a member instance of the most recent Gesture. Something like:

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

Then in your onSaveInstanceState, simply get and package the member instance instead of calling getGesture(). Now setGesture() should work as expected when the Activity recreates itself.

江湖彼岸 2024-11-09 00:33:18

在清单中使用 android:configChanges="fontScale|uiMode|screenLayout|navigation|touchscreen|mcc 或尝试 onSavedInstance;

Use android:configChanges="fontScale|uiMode|screenLayout|navigation|touchscreen|mcc in manifest or try onSavedInstance;

小兔几 2024-11-09 00:33:18

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

android:screenOrientation="肖像"

When the orientation changes it restarts the activity. You could try restrict the orientation of the app in the manifest file.

android:screenOrientation="portrait"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文