I'm making some sort of clone for FlappyBird, but with some adjustments.

I'm trying to have an animated background running infinitely times. I already have the picture mirrored so the flow will be clear as possible. Problem is, the gameplay itself (my GameView class) doesn't have any XML layout, so I can't use the regular way with the following code:

        ImageView bg1 = findViewById(R.id.bg1);
        ImageView bg2 = findViewById(R.id.bg2);

        ValueAnimator animator=ValueAnimator.ofFloat(0.0f,1.0f);
        animator.setInterpolator(new LinearInterpolator());
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final float prog = (float) animation.getAnimatedValue();
                final float wid = bg1.getWidth();
                final float translationX = wid*prog;

Is there a way I can change the ImageView to Bitmap (couldn't find alternative to ImageView's setTranslationX)? If not, is there a possible to relate the class to certain XML layout without using setContentView() (my class doesn't relay or change any XML layout)?

Thank you in advance!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.