【发布时间】:2012-11-13 21:58:26
【问题描述】:
(安卓)
我正在努力使全屏模拟时钟应用程序适应动态壁纸。
该应用程序使用三个独立的ImageView 表示时针、分针、秒针和RotateAnimation。
我一直在寻找一种在动态壁纸中使用 ImageView 的方法。 this 和 this 表示这应该可以使用 measure() 和 layout(),但我
真的不知道怎么用。
例如,我使用下面的代码将clock_background.png 加载到ImageView 中。
public class MyWallpaperService extends WallpaperService {
@Override
public Engine onCreateEngine() {
return new MyWallpaperEngine();
}
....
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
mContext = getBaseContext();
backgroundImage = new ImageView(mContext);
backgroundImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.clock_background));
}
}
后来我有:
backgroundImage.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
backgroundImage.layout(0, 0, 150, 150);
我希望上面的代码会在左上角显示clock_background.png
屏幕。我试图将上面的两行放在OnSurfaceCreated 和OnSurfaceChanged 中。不幸的是,它不起作用。
据我了解,动态壁纸提供了一个 Surface(不是 SurfaceView),可以从中获取
画布并在上面画东西。
我为在 Android 上的新手而道歉:我做错了吗?我只是不想
惹drawBitmap或点赞,反正我也不在乎电池。
非常感谢任何帮助。非常感谢!
【问题讨论】:
标签: android imageview android-relativelayout wallpaper android-framelayout