关于具有自动翻转功能的viewflipper

时间:2011-11-11 07:24:16

标签: android viewflipper

现在我可以使用滑动翻转视图。我想在说5秒后自动翻转视图。

我必须根据手势识别翻转视图的代码是:

class MyGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                viewFlipper.setInAnimation(slideLeftIn);
                viewFlipper.setOutAnimation(slideLeftOut);

                if (currentIndex == maxIndex) {
                    currentIndex = 0;
                } else {
                    currentIndex = currentIndex + 1;
                }
                if (currentView == 0) {
                    currentView = 1;
                    ImageView iv = (ImageView) findViewById(R.id.one);
                    /*iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));*/
                    Bitmap mBitmap=BitmapFactory.decodeFile(ImageList.get(currentIndex));
                    iv.setImageBitmap(mBitmap);
                    Log.d("image list index!!", ImageList.get(currentIndex));
                    System.gc();

                } else if (currentView == 1) {
                    currentView = 2;
                    ImageView iv = (ImageView) findViewById(R.id.two);
                    /*iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));*/
                    Bitmap mBitmap=BitmapFactory.decodeFile(ImageList.get(currentIndex));
                    iv.setImageBitmap(mBitmap);
                    Log.d("image list index!!", ImageList.get(currentIndex));

                    System.gc();
                } else {
                    currentView = 0;
                    ImageView iv = (ImageView) findViewById(R.id.zero);
                    /*iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    */
                    Bitmap mBitmap=BitmapFactory.decodeFile(ImageList.get(currentIndex));
                    iv.setImageBitmap(mBitmap);
                    Log.d("image list index!!", ImageList.get(currentIndex));

                    System.gc();
                }
                Log.v("ImageViewFlipper", "Current View: " + currentView);
                viewFlipper.showNext();
                viewFlipper.startFlipping();
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                viewFlipper.setInAnimation(slideRightIn);
                viewFlipper.setOutAnimation(slideRightOut);
                if (currentIndex == 0) {
                    currentIndex = maxIndex;
                } else {
                    currentIndex = currentIndex - 1;
                }
                if (currentView == 0) {
                    currentView = 2;
                    ImageView iv = (ImageView) findViewById(R.id.two);
                    iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    System.gc();
                } else if (currentView == 2) {
                    currentView = 1;
                    ImageView iv = (ImageView) findViewById(R.id.one);
                    iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    System.gc();
                } else {
                    currentView = 0;
                    ImageView iv = (ImageView) findViewById(R.id.zero);
                    iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    System.gc();
                }
                Log.v("ImageViewFlipper", "Current View: " + currentView);
                viewFlipper.showPrevious();
            }
        } catch (Exception e) {
            // nothing
        }
        return false;

    }

}

我现在正在使用viewFlipper.showNext()和showPrevious()方法进行翻转。 我尝试使用

       viewFlipper.setFlipInterval(1000);

和viewFlipper.startFlipping(); 方法。我现在面临的问题是有3个图像视图我需要连续一个接一个地加载(并且图像视图应该在每个图像视图中随着它们移动而改变)。这不会发生。我只能看到2个固定图像只是一个接一个地显示,而其内容没有任何变化。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

看看startFlipping() 和ViewFlipper类中的setFlipInterval()方法

http://android-er.blogspot.com/2011/03/auto-flipping-of-viewflipper.html

按照上面的link.hope帮助