0

I'm trying to make an app with 25 ImageView using ViewFlipper. But when I put more than 15 ImageView I got FC. I know it is a memory issue. I hope you guys help me to destroy each 2 views so I don't get any memory problem (FC). Or give me alternative. Here is my code:

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;

    }

}
David
  • 11
  • 3

1 Answers1

0

over shooting memory budget with view flipper you cant acheive that, flipper requires all the views associated with it to be loaded in memory all the time, you can fix this by following

  1. Loading compressed Images in memory rather then image with full size, this will give you more room to load images, read about it here Out of memory

  2. Either implement your logic, by fargments and View pager. like you have one activity, one fragment for displaying image and View pager to supply you pages just like flipper, here you have adapter mechanism associated so no memory issues, read about it here View Pager Implementing view pager

  3. and last but not the least, explore about android List view its amazing and powerfull tool for displaying a list of contents.

Community
  • 1
  • 1
Techfist
  • 4,314
  • 6
  • 22
  • 32
  • I'm still beginner in developing. I want to implement it with fragments and view pager since my app idea is to share each images that you are sliding it. Any good suggestion or a sample which can help swipe without memory issue and in the same time I can add sharing button on. Thanks – David Aug 14 '14 at 08:01
  • Please check the link which i have mentioned in second point "Implementing View Pager". – Techfist Aug 14 '14 at 09:05
  • I checked the sample but it doesn't work for me, it gives me error in the gen. I tried to clean project but the problem still persists.Any solution or alternative, please. Thanks – David Aug 14 '14 at 13:40