循环浏览 ImageView 的位图
Cycling through bitmaps for ImageView
通过 python 中的 Flask,我已将多个图像发送到我的 Android 应用程序并将它们存储到位图的 ArrayList
如何在无限循环的动画中以淡入淡出的方式自动循环 out/fade?
是的,你可以按照下面的方式做:(这里,为了演示,我使用了一个可绘制的数组。你可以使用你的位图数组代替这个,或者用这个来演示。)
public class Main3Activity extends AppCompatActivity {
private ImageView imageView;
private int imageArray[] = { R.drawable.ic_launcher_background, R.drawable.ic_launcher_background,R.drawable.ic_launcher_background };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
imageView = (ImageView) findViewById(R.id.imageView);
startAnimation();
}
private void startAnimation() {
int fadeInDuration = 500;
int timeBetween = 3000;
int fadeOutDuration = 1000;
int random = new Random().nextInt((imageArray.length - 1) + 1);
imageView.setVisibility(View.INVISIBLE);
imageView.setImageResource(imageArray[random]);
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator());
fadeIn.setDuration(fadeInDuration);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(fadeInDuration + timeBetween);
fadeOut.setDuration(fadeOutDuration);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
animation.setRepeatCount(1);
imageView.setAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
startAnimation();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
}
}
通过 python 中的 Flask,我已将多个图像发送到我的 Android 应用程序并将它们存储到位图的 ArrayList
如何在无限循环的动画中以淡入淡出的方式自动循环 out/fade?
是的,你可以按照下面的方式做:(这里,为了演示,我使用了一个可绘制的数组。你可以使用你的位图数组代替这个,或者用这个来演示。)
public class Main3Activity extends AppCompatActivity {
private ImageView imageView;
private int imageArray[] = { R.drawable.ic_launcher_background, R.drawable.ic_launcher_background,R.drawable.ic_launcher_background };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
imageView = (ImageView) findViewById(R.id.imageView);
startAnimation();
}
private void startAnimation() {
int fadeInDuration = 500;
int timeBetween = 3000;
int fadeOutDuration = 1000;
int random = new Random().nextInt((imageArray.length - 1) + 1);
imageView.setVisibility(View.INVISIBLE);
imageView.setImageResource(imageArray[random]);
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator());
fadeIn.setDuration(fadeInDuration);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(fadeInDuration + timeBetween);
fadeOut.setDuration(fadeOutDuration);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
animation.setRepeatCount(1);
imageView.setAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
startAnimation();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
}
}