Вы создаете отдельный макет с динамически вставленным изображением (image_layout.xml):
<ImageView
android:id="@+id/anim_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="..."/>
Далее используйте «inflater»:
ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main);
v = (ViewGroup) getLayoutInflater().inflate(R.layout.image_layout, mainLayout, false);
mainLayout.addView(v);
final ImageView backgroundOne = (ImageView) v.findViewById(R.id.anim_image);
Завершено:
ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main);
v = (ViewGroup) getLayoutInflater().inflate(R.layout.image_layout, mainLayout, false);
mainLayout.addView(v);
final ImageView backgroundOne = (ImageView) v.findViewById(R.id.anim_image);
final ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(10000L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float progress = (float) animation.getAnimatedValue();
final float width = v.getWidth();
final float translationX = width * progress;
v.setTranslationX(translationX);
v.setTranslationX(translationX - width);
}
});
animator.start();