一个动态壁纸可以锁定屏幕为横屏模式吗?

3

一个动态壁纸能够锁定屏幕为竖屏模式吗?如果可以,如何操作?

我应该提一下,在stackoverflow(SO)上面有两个看似是这个问题的答案。一个答案过于复杂,我并没有完全理解它,并且那个答案并未被原始贴文发布者接受。第二个答案对我也不起作用。

第三个答案涉及到使用:

android:screenOrientatin = "portrait" or "landscape"

有人建议将android:screenOrientation =“portrait”添加到清单中,但不清楚应该放在哪里。

编辑:已尝试将android:screenOrientation =“portrait”放置在清单的许多不同位置,但没有一个起作用。

编辑:另一个答案是旋转位图并通过侧面绘制一切来处理旋转-但这看起来非常丑陋,因为当您旋转手机时,操作系统会启动旋转动画-这意味着随着您转动手机,会出现可怕的跳跃效果。


1
请在我得到一个明确且可行的答案之前不要关闭这个问题。 - Mick
创建一个不可见的视图,这对我来说很有效 :) https://dev59.com/LmUq5IYBdhLWcg3wVu-D - Matthew
4个回答

2
我开始怀疑真正的答案可能只是“不行”。

0
在你的 AndroidManifest.xml 文件中,应该有类似以下的内容:
    <application
    android:icon="@drawable/app_icon"
    android:label="@string/nuboLogin"
    android:name=".LoginApplication" 
     android:debuggable="true">
    <activity
        android:name=".WallPaperActivity"
        android:label="@string/wallPaper" 
        android:windowSoftInputMode="adjustPan" 
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden">
    </activity>

这将确保您的Activity在纵向模式下运行。如果您喜欢横向模式,您可以轻松猜测应该修改什么。


壁纸是一个“服务”,而不是一个活动...但无论如何,我尝试添加android:screenOrientation="portrait",但没有效果 :-( - Mick

0

当屏幕方向发生改变时,Android应用程序会重新启动活动。您可以选择使用

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.
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.

0
你尝试过使用 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 吗?

setRequestedOrientation 在 WallpaperService 中似乎未定义。 - Mick
也许你需要实现类似于Activity的东西? - Leo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接