gpt4 book ai didi

android - 在一个 imageView 中一个接一个地显示多张图片,并反复从左到右翻转效果

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:43:23 24 4
gpt4 key购买 nike

假设我在可绘制文件夹中有多个图像(前 8 个图像)。我想在一个 imageView 中一个接一个地显示所有这些图像,并反复从左到右翻转效果(ex-img[0],img[1],……img[8],img[0],img[ 1],…………).我该怎么做?

private void AnimateandSlideShow() {
image1 = (ImageView)findViewById(R.id.imageView1);
image1.setImageResource(img[currentimageindex1%img.length]);
currentimageindex1++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
image1.startAnimation(rotateimage);
}

最佳答案

使用自定义函数使用间隔处理程序旋转图像来改变图像,这里我改变图像反方向:

    private ImageView image1;
private int[] imageArray;
private int currentIndex;
private int startIndex;
private int endIndex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

image1 = (ImageView)findViewById(R.id.imageView1);
imageArray = new int[8];
imageArray[0] = R.drawable.one;
imageArray[1] = R.drawable.two;
imageArray[2] = R.drawable.three;
imageArray[3] = R.drawable.four;
imageArray[4] = R.drawable.five;
imageArray[5] = R.drawable.six;
imageArray[6] = R.drawable.seven;
imageArray[7] = R.drawable.eight;

startIndex = 0;
endIndex = 7;
nextImage();


}

public void nextImage(){
image1.setImageResource(imageArray[currentIndex]);
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
image1.startAnimation(rotateimage);
currentIndex++;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(currentIndex>endIndex){
currentIndex--;
previousImage();
}else{
nextImage();
}

}
},1000); // here 1000(1 second) interval to change from current to next image

}
public void previousImage(){
image1.setImageResource(imageArray[currentIndex]);
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
image1.startAnimation(rotateimage);
currentIndex--;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(currentIndex<startIndex){
currentIndex++;
nextImage();
}else{
previousImage(); // here 1000(1 second) interval to change from current to previous image
}
}
},1000);

}

关于android - 在一个 imageView 中一个接一个地显示多张图片,并反复从左到右翻转效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27167866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com