开发者

Portrait mode in livewallpaper question?

I have a livewallpaper and I want to my wallpaper work in portrait mode only. Can I do it?

<application
        android:label="@string/wallpaper_name"
        android:debuggable="true"
        android:screenOrientation="portrait"
        android:icon="@drawable/icon">
        <service
            android:label="@string/wallpaper"
            android:name=".LiveWallpaper"
            android:permission="android.permission.BIND_WALLPAPER">
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data 
                android:name="android.service.wallpaper" 
                android:resource="@xml/weather_wallpaper" />
        </service>
</application>
开发者_StackOverflow社区

I try this, but it does't work, because there is not android:screenOrientation in application tag.


I'm a little puzzled by your question: by default, live wallpapers generally remain locked in portrait mode, to correspond to the behavior of the default launcher. Are you saying that your wallpaper is automatically shifting into landscape mode when you rotate the phone? If that's true, please tell us:
1) Do the live wallpapers that came with your phone (Polar Clock, Grass, Cube from SDK, etc.) shift into landscape mode when you rotate your phone, too?
2) Are you using a custom launcher? Do its icons/widgets rotate when you rotate your phone?
Please let us know and we'll try to help. :-)

Edit: I have not seen this spelled out clearly anywhere in black and white, but my impression is that we live wallpaperers are generally at the mercy of the launcher being used. As previously mentioned, most devices come with launchers that do not respond to orientation changes, so the surface they give you doesn't either. I know some custom launchers do respond to orientation changes, but I did not realize until puzzling out your question that the emulator's launcher does, too. My best guess is that you cannot prevent a custom launcher (including the emulator) from rotating your canvas. However, you can detect and compensate for this, if you want. In onSurfaceChanged, you can check if your width is greater than your height, and if it is, you can query the orientation using the technique shown here: http://www.codeproject.com/KB/android/AndroidLiveWallpaper.aspx
Then you can just rotate your canvas back into portrait mode before you draw, and it should all be good. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜