【问题标题】:Can a live wallpaper lock the screen in portrait mode?动态壁纸可以在纵向模式下锁定屏幕吗?
【发布时间】:2013-04-23 17:12:17
【问题描述】:

动态壁纸可以在纵向模式下锁定屏幕吗?如果有,怎么做?

我应该提一下,我在 SO 上看到了这个问题的两个假设答案,一个看起来非常复杂,我没有完全理解,并且原始发布者不接受答案。第二个答案对我不起作用。

第三个答案涉及使用:

android:screenOrientatin = "portrait" or "landscape"

已被建议,但不清楚它应该在清单中的确切位置。

编辑:已尝试将 android:screenOrientation="portrait" 放在清单中的许多不同位置,但都没有奏效。

编辑: 另一个答案是旋转你的位图并通过将所有内容横向绘制来处理旋转 - 但这看起来非常难看,因为当你旋转手机时,操作系统会启动旋转动画 - 这意味着当你转动手机时你会得到一个可怕的跳跃效果。

【问题讨论】:

标签: android live-wallpaper wallpaper


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    你试过setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);吗?

    【讨论】:

    • setRequestedOrientation 似乎未为 WallpaperService 定义
    • 也许你必须实现类似 Activity 的东西?
    【解决方案3】:

    在您的 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 以纵向模式运行。如果你更喜欢横向,你可以很容易猜出你应该修改什么

    【讨论】:

    • wallpapr 是“服务”而不是活动...但无论如何我尝试添加 android:screenOrientation="portrait" 并没有效果:-(
    【解决方案4】:

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

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 2010-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多