我目前无法使用动态壁纸进行一些非常密集的绘图。但是,在测试我的代码时,我发现壁纸是滞后的,并且在屏幕旋转时会被破坏。
在我的绘制方法中,我有这个:
mRectArray = new Rect[] {
new Rect(0, 0, c.getWidth(),
(c.getHeight() + statusBarHeight) / 20),
new Rect(0, (c.getHeight() + statusBarHeight) / 20,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 2),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 2,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 3),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 3,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 4),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 4,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 5),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 5,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 6),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 6,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 7),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 7,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 8),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 8,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 9),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 9,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 10),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 10,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 11),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 11,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 12),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 12,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 13),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 13,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 14),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 14,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 15),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 15,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 16),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 16,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 17),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 17,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 18),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 18,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 19),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 19,
c.getWidth(),
(c.getHeight() + statusBarHeight) / 20 * 20),
new Rect(0, 0, right1,
(c.getHeight() + statusBarHeight) / 20),
new Rect(0, (c.getHeight() + statusBarHeight) / 20, right2,
(c.getHeight() + statusBarHeight) / 20 * 2),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 2,
right3, (c.getHeight() + statusBarHeight) / 20 * 3),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 3,
right4, (c.getHeight() + statusBarHeight) / 20 * 4),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 4,
right5, (c.getHeight() + statusBarHeight) / 20 * 5),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 5,
right6, (c.getHeight() + statusBarHeight) / 20 * 6),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 6,
right7, (c.getHeight() + statusBarHeight) / 20 * 7),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 7,
right8, (c.getHeight() + statusBarHeight) / 20 * 8),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 8,
right9, (c.getHeight() + statusBarHeight) / 20 * 9),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 9,
right10,
(c.getHeight() + statusBarHeight) / 20 * 10),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 10,
right11,
(c.getHeight() + statusBarHeight) / 20 * 11),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 11,
right12,
(c.getHeight() + statusBarHeight) / 20 * 12),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 12,
right13,
(c.getHeight() + statusBarHeight) / 20 * 13),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 13,
right14,
(c.getHeight() + statusBarHeight) / 20 * 14),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 14,
right15,
(c.getHeight() + statusBarHeight) / 20 * 15),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 15,
right16,
(c.getHeight() + statusBarHeight) / 20 * 16),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 16,
right17,
(c.getHeight() + statusBarHeight) / 20 * 17),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 17,
right18,
(c.getHeight() + statusBarHeight) / 20 * 18),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 18,
right19,
(c.getHeight() + statusBarHeight) / 20 * 19),
new Rect(0, (c.getHeight() + statusBarHeight) / 20 * 19,
right20,
(c.getHeight() + statusBarHeight) / 20 * 20),
new Rect(c.getWidth() / 20, c.getHeight() / 15,
c.getWidth() / 20 * 8, c.getHeight() / 15 * 4),
new Rect(c.getWidth() / 20, c.getHeight() / 15,
c.getWidth() / 20 * 8, c.getHeight() / 15 * 8), };
这是40个矩形,不断在onDraw上初始化。 现在,问题是这些矩形必须不断初始化,因为我正在为20个矩形的右侧设置动画......
我还有另外40个if语句用于动画矩形..
如何压缩我的代码以免牺牲性能?
答案 0 :(得分:0)
使用onSurfaceChange()函数的高度和宽度在onSurfaceChange()中初始化数组。