Android mueve el fondo continuamente con animación
Lo que quiero hacer es mover el fondo horizontalmente y hacer que se repita infinitamente.
Intenté usar unImageSwitcher
con animación para dar este efecto, pero no pudo hacer que funcione correctamente. Este es el código que tengo hasta ahora.
public class MainActivity extends AppCompatActivity implements ViewSwitcher.ViewFactory {
private Animation animSlide;
private ImageSwitcher image;
private ImageView imagePop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageSwitcher) findViewById(R.id.image_switcher);
image.setFactory(this);
image.setImageResource(R.drawable.zc06);
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
in.setDuration(10000);
Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
out.setDuration(10000);
image.setInAnimation(in);
image.setOutAnimation(out);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
image.setImageResource(R.drawable.zc06);
}
});
}
}, 0, 10000);
Animation mZoomInAnimation = AnimationUtils.loadAnimation(this, R.anim.zoom_in);
Animation mZoomOutAnimation = AnimationUtils.loadAnimation(this, R.anim.zoom_out);
imagePop.startAnimation(mZoomInAnimation);
imagePop.startAnimation(mZoomOutAnimation);
}
@Override
public View makeView() {
ImageView myView = new ImageView(getApplicationContext());
return myView;
}
}