0

現在、非常に集中的な描画を行うライブ壁紙で問題が発生しています。ただし、コードをテストしたところ、壁紙が遅く、画面が回転すると破壊されていることがわかりました。

私の描画メソッド内にこれがあります:

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), };

これは、onDrawで常に初期化されている40個の長方形です。ここで問題となるのは、20個の長方形の右側をアニメートしているため、これらの長方形は常に初期化する必要があるということです...

長方形をアニメーション化するためのifステートメントがさらに40個ほどあります。

パフォーマンスを犠牲にしないようにコードを圧縮するにはどうすればよいですか?

4

1 に答える 1

0

onSurfaceChange() 関数の高さと幅を使用して、onSurfaceChange() で配列を初期化します。

于 2012-06-16T18:04:56.777 に答える