如何在创建活动之前定义屏幕方向?

发布于 2024-11-25 12:17:17 字数 245 浏览 6 评论 0原文

我将我的活动定义为仅处于纵向模式: android:screenOrientation="portrait"

当我通过意图使用相机功能拍照时,以横向模式拍摄这张照片并在保存时将屏幕切换为纵向模式,我再次返回到我的活动。我不明白的是,我的 Activity 短时间内处于横向模式,被销毁,然后以纵向模式再次构建...由于我的 onCreate 和 onRestore 函数需要一些时间,用户的等待时间增加了一倍..是否

有解决方法或其他方法?

I defined my activity to only be in portrait mode by :
android:screenOrientation="portrait"

When I take a picture with the camera function via intent, take this picture in landscape mode and turn the screen to portrait mode when saving it, i return to my activity again. What I dont understand is, that my activity for a short time is in landscape mode, is destroyed and then built again in portrait mode... as my onCreate ond onRestore functions need some time, the waiting time for the user is doubled...

Is there a workaround or something else?

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

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

发布评论

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

评论(2

笔芯 2024-12-02 12:17:17

您还可以注册您的活动以显式处理任何方向更改,方法是将 android:configChanges="orientation" 添加到活动定义中,然后重写活动中的 onCofigurationChanged 方法,如下所示:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

我不确定是否它将有助于解决您的具体问题,但我记得当我希望某个活动仅以纵向模式显示时这样做。如果有帮助请告诉我:)

You can also register your activity to explicitly handle any orientation changes by adding android:configChanges="orientation" to the activity definition and then overriding the onCofigurationChanged method in your activity like this:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

I'm not sure if it would help with your specific problem, but I remember doing this when I wanted an activity to only display in portrait mode. Let me know if it helps :)

只是在用心讲痛 2024-12-02 12:17:17

android:configChanges="orientation" 添加到您的 标记中。这样,活动将不会在方向更改时重新创建,而只会收到回调 onConfigurationChanged ,您可以忽略该回调。

Add android:configChanges="orientation" to your <activity> tag. This way the activity will not be recreated on orientation change, but will just receive a callback onConfigurationChanged which you can ignore.

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