使用超过15张图像的Viewflipper

时间:2014-08-14 06:25:16

标签: android imageview viewflipper flip

我正在尝试使用ViewFlipper制作一个带有25个ImageView的应用。但是当我放置超过15个ImageView时,我得到了FC。我知道这是一个记忆问题。我希望你们帮助我销毁每个2个视图,这样我就不会遇到任何内存问题(FC)。或者给我另类。这是我的代码:

public class ImageAdapterGroup extends Activity {
    private ViewFlipper viewFlipper;
    private float lastX;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_p);

// Method to handle touch event like left to right swap and right to left
    // swap
    public boolean onTouchEvent(MotionEvent touchevent) {
        switch (touchevent.getAction()) {
        // when user first touches the screen to swap
        case MotionEvent.ACTION_DOWN: {
            lastX = touchevent.getX();
            break;
        }
        case MotionEvent.ACTION_UP: {
            float currentX = touchevent.getX();

            // if left to right swipe on screen
            if (lastX < currentX) {
                // If no more View/Child to flip
                if (viewFlipper.getDisplayedChild() == 0)
                    break;

                // set the required Animation type to ViewFlipper
                // The Next screen will come in form Left and current Screen
                // will go OUT from Right
                viewFlipper.setInAnimation(this, R.anim.in_from_left);
                viewFlipper.setOutAnimation(this, R.anim.out_to_right);
                // Show the next Screen
                viewFlipper.showNext();
            }

            // if right to left swipe on screen
            if (lastX > currentX) {
                if (viewFlipper.getDisplayedChild() == 1)
                    break;
                // set the required Animation type to ViewFlipper
                // The Next screen will come in form Right and current Screen
                // will go OUT from Left
                viewFlipper.setInAnimation(this, R.anim.in_from_right);
                viewFlipper.setOutAnimation(this, R.anim.out_to_left);
                // Show The Previous Screen
                viewFlipper.showPrevious();
            }
            break;
        }
        }
        return false;

    }

}

1 个答案:

答案 0 :(得分:0)

超过使用视图鳍状肢拍摄内存预算你无法实现,鳍状肢需要将与其关联的所有视图一直加载到内存中,您可以通过以下方式解决此问题

  1. 在内存中加载压缩图像而不是全尺寸图像,这样可以为您提供更多空间来加载图像,在此处阅读Out of memory

  2. 通过fargments和View寻呼机实现您的逻辑。就像你有一个活动,一个片段用于显示图像和查看寻呼机为你提供像鳍状肢一样的页面,这里你有适配器机制关联所以没有内存问题,请在这里阅读View Pager Implementing view pager

  3. 最后但并非最不重要的是,探索Android列表视图,它是用于显示内容列表的神奇而强大的工具。