在一幅图像中显示多幅图像反复观看,一次又一次地从左向右翻转 [英] Show multiple images in a imageView one after another with left to right flip effect repeatedly

查看:66
本文介绍了在一幅图像中显示多幅图像反复观看,一次又一次地从左向右翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在可绘制文件夹中有多个图像(例如8个图像).我想一次又一次地在图像视图中以左右翻转的方式显示所有这些图像( ex-img [0],img [1],……img [8],img [0],img [1],…………).我该怎么办?

Suppose I have multiple images in drawable folder(ex-8 images). I want to show all these images in a imageView one after another with left to right flip effect repeatedly(ex-img[0],img[1],……img[8],img[0],img[1],…………). How can I do this?

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);         
}

推荐答案

使用自定义函数使用处理程序旋转图像以间隔更改图像,在此我改变图像的反方向:

Use custom function rotate image using handler for interval to change image,here i change image vice verse direction :

    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);

    }

这篇关于在一幅图像中显示多幅图像反复观看,一次又一次地从左向右翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆