I have created a live wallpaper It is working fine in portrait mode but when i put the phone in Landscape mode the view does not appear properly.Now what i want to do is "To fix the screen orientation in portrait mode". How can i do this for a live wallpaper? I tried to rotate the bitmap and the canvas but it is appear not as good. Is there any tutorial on rotating the canvas and bitmap? Please suggest and please advice me for my problem. Thanks in advance.
问问题
2800 次
1 回答
1
请看一下我的代码:
public class PonyWallpaper extends AnimationWallpaper {
/*some code here*/
class PonyEngine extends AnimationEngine {
/*some code here as well*/
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
Log.v("orientation changed", "w: "+width + " h: " + height + " width desired: " + this.getDesiredMinimumWidth() + " height desired: " + this.getDesiredMinimumHeight());
AnimationEngine 声明为
protected abstract class AnimationEngine extends android.service.wallpaper.WallpaperService.Engine
从横向切换到纵向时的输出:
方向改变(352):w:800 h:480 所需宽度:960 所需高度:800
从纵向切换到横向时的输出:
方向改变(352):w:480 h:800 所需宽度:960 所需高度:800
如您所见,每次更改方向时都会调用 android.service.wallpaper.WallpaperService.Engine 类的 onSurfaceChanged 方法。
据我观察,
this.getDesiredMinimumWidth()
和
this.getDesiredMinimumHeight()
不要改变并且是宽度和高度的最大可能值。
我的解决方案是:
- 将宽度、所需宽度、高度和所需高度传递给我的抽屉对象的方法;
- 调用 drawObject() - 坐标范围从 0.0 到 1.0 的方法;
- 将抽屉对象内的这些值缩放到由所需宽度和所需高度描述的逻辑坐标;
- 通过传递的 xPixelOffset 来设置真实 x 坐标的偏移量
onOffsetsChanged
的方法
android.service.wallpaper.WallpaperService.Engine
- 根据实际高度和所需高度的差异来设置实际 y 坐标的偏移量。
我希望这会有所帮助!
于 2012-05-20T20:49:16.813 回答