安卓移动背景连续与动画
2022-09-01 18:05:29
我想做的是水平移动背景,让它无限重复。
我尝试使用带有动画的动画来提供这种效果,但无法使其正常工作。这是我到目前为止的代码LImageSwitcher
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;
}
}