java - 如何在android中设置循环背景

标签 java android

我想做的很简单。我想要一个循环背景,这样看起来地面在移动。这是我尝试执行此操作的方法,但看起来两张图片都是同时发送的。

 public void moveGround(){
        startingXPosition =1500.0f;
        endingXPosition = -1500.0f;
        startingYPosition =0.0f;
        endingYPosition =0.0f;
        ImageView ground = (ImageView)findViewById(R.id.ground);
        TranslateAnimation groundAnimation = new TranslateAnimation(startingXPosition,endingXPosition,startingYPosition,endingYPosition);
        groundAnimation.setDuration(1500);
        groundAnimation.setRepeatCount(Animation.INFINITE);
        ground.startAnimation(groundAnimation);

        if(ground.getLeft()<=0) {
            float startingXPosition2 = 1500.0f;
            float endingXPosition2 = -1500.0f;
            float startingYPosition2 = 0.0f;
            float endingYPosition2 = 0.0f;
            ImageView ground2 = (ImageView) findViewById(R.id.ground2);
            TranslateAnimation groundAnimation2 = new TranslateAnimation(startingXPosition2, endingXPosition2, startingYPosition2, endingYPosition2);
            groundAnimation2.setDuration(1500);
            groundAnimation2.setRepeatCount(Animation.INFINITE);
            ground2.startAnimation(groundAnimation2);
        }

    }

最佳答案

尝试

yourAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // do what you want
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
              // do what you want
            }
        });

关于java - 如何在android中设置循环背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32010631/

相关文章:

java - 我可以从 Linux CLI 获得多少有关 JBoss 的信息

java - 我可以有一个没有键的非空 HashMap 吗?

android - 在三星 Galaxy S 上调用 RingTonePreference 时出现 NullPointerException

android - 如何在不使用 facebook 注销按钮的情况下以编程方式从 facebook SDK 4.7 注销?

android - 在 SimpleCursorAdapter 中使用 AsyncTask

java - 如何在云端模拟批量运行?

java - Derby Eclipse 类路径

java - JTextField特定格式检查

android - 从 listView 填充 editText

Activity onCreate 中的 java.util.ConcurrentModificationException