Android背景动画滞后游戏

时间:2014-09-07 02:55:48

标签: android animation background android-animation android-resources

我测试过将ImageView设置为带有一些较小的png文件的动画列表并且没有问题,但是尝试将其用于RelativeLayout的背景,但会导致一些严重的滞后。当我使用16个png图像中的前5个时发生这种情况,我注意到如果由于内存越界而添加所有这些图像,它将无法运行。这是相关代码(onFinish()就在倒数计时器停止时): 主要方法:

@Override
    public void onFinish() {
        count.setText("Go!");
        playing = true;
        startTime = System.currentTimeMillis();
        score.setVisibility(View.VISIBLE);

        //Start background animation
        RelativeLayout rl = (RelativeLayout) findViewById(R.id.main);
        rl.setBackgroundResource(R.drawable.background);
        AnimationDrawable frameAnimation = (AnimationDrawable) rl.getBackground();
        frameAnimation.start();
    }

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background"
tools:context=".MainActivity" >

动画列表:

<?xml version="1.0" encoding="utf-8"?>
<animation-list 
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item android:drawable="@drawable/background_0" android:duration="50"/>
<item android:drawable="@drawable/background_1" android:duration="50" />
<item android:drawable="@drawable/background_1" android:duration="50" />
<item android:drawable="@drawable/background_2" android:duration="50" />
<item android:drawable="@drawable/background_3" android:duration="50" />
<item android:drawable="@drawable/background_4" android:duration="50" />
<item android:drawable="@drawable/background_5" android:duration="50" />

</animation-list>

以下是一些有问题的图片,以防他们出现问题http://imgur.com/a/vEmKn

1 个答案:

答案 0 :(得分:5)

您是否尝试将所有相关图片/ png移动到

  

抽拉-nodpi

你的res文件夹里面的

文件夹?

相关问题