AnimationDrawable持续时间属性

时间:2011-08-31 18:07:48

标签: android android-animation

我的xml文件中有android:duration属性的问题。 那是我的代码:

<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/eye_1"
android:duration="150" />
<item
.
.
.
</animation-list>

共有8张图片。 这是我的活动代码:

    public class MyActivity extends Activity {
    AnimationDrawable frameAnimation;
    private MediaPlayer mp;
    @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sauron);
        mp = MediaPlayer.create(this, R.raw.sound);
        mp.setLooping(true);
        mp.start();

        ImageView imgView = (ImageView) findViewById(R.id.animationImage);
        // imgView.setVisibility(ImageView.VISIBLE);
        imgView.setBackgroundResource(R.drawable.animation);

        frameAnimation = (AnimationDrawable) imgView
                .getBackground();


     // Get instance of Vibrator from current Context
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(10000);
    }
    @Override public void onWindowFocusChanged(boolean hasFocus) { 
        frameAnimation.start(); 
        super.onWindowFocusChanged(hasFocus); }

@Override
    protected void onStop()
{
    // Stop play
    super.onStop();
    mp.stop();
}
    }

一切正常但图像之间的持续时间存在问题。无论我在android:duration属性中放入什么数字,动画运行速度都非常快。有谁知道问题出在哪里?

谢谢

1 个答案:

答案 0 :(得分:0)

持续时间以“毫秒”表示,150表示非常快 当1500是1.5秒而150意味着0.15秒,刚刚超过十分之一秒

尝试将数字设置为数千,例如1500或3000,看看是否有效

相关问题