打开应用程序并更改方向时防止动态壁纸方向发生变化?

发布于 2024-10-06 12:22:06 字数 215 浏览 8 评论 0原文

我编写的动态壁纸遇到方向问题。基本上,画布将根据其上方打开的应用程序进行旋转。我对此进行了测试,并意识到当我从之前打开的方向已更改的应用程序返回主屏幕时, onSurfaceChanged() 方法将被触发。

我想一个更好的问题是,为什么当应用程序打开并且其方向发生变化时,我的动态壁纸表面会发生变化?有没有办法防止我的动态壁纸方向不断变化?谢谢,希望这是有道理的?

I'm having an orientation issue with a Live Wallpaper that I wrote. Basically the canvas will rotate depending on the application opened above it. I tested this and realized that the onSurfaceChanged() method is firing when I return to the home screen from a previously opened application who's orientation was changed.

I suppose a better question would be, why does my Live Wallpaper Surface Change when an application is opened and it's orientation changed? Is there a way to prevent my Live Wallpaper orientation from ever changing? Thanks, hope that makes sense?

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

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

发布评论

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

评论(2

鯉魚旗 2024-10-13 12:22:06

您可以使用以下方法从 android.service.wallpaper.WallpaperService.Engine 类中处理屏幕方向:

public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height)

...只需相应地处理事件。

不能android:configChangesandroid:screenOrientation添加到WallpaperService!
(您在创建动态壁纸时使用的)

我会将此添加为“Anirudha”答案的评论,但我没有足够的声誉来这样做。

You can handle screen orientation from within the android.service.wallpaper.WallpaperService.Engine class with the following method:

public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height)

... just handle the event accordingly.

You CANNOT add android:configChanges nor android:screenOrientation to a WallpaperService!
(Which you are using when creating a live wallpaper)

I would have added this as a comment to "Anirudha"'s answer, but I don't have enough reputation to do so.

望她远 2024-10-13 12:22:06

当方向改变时,Android 应用程序会重新启动 Activity。
您可以

  1. 在清单中使用android:configChanges。当运行时发生配置更改时,默认情况下活动会关闭并重新启动,但使用此属性声明配置将阻止活动重新启动。相反,该 Activity 仍保持运行状态并调用其 onConfigurationChanged() 方法。
  2. 使用 android:screenOrientatin = "portrait" 或 "landscape" 它将强制应用程序以您指定的模式运行。但是,它不会阻止活动被关闭和重新启动。

Android application restarts the activity when the orientation changes.
You can either use

  1. android:configChanges in your manifest. The activity is shut down and restarted by default, when a configuration change occurs at runtime, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
  2. use android:screenOrientatin = "portrait" or "landscape" it will force the app to run in the mode you specify. However it will not prevent the activity from being shut down and restarted.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文