0

I'm using view flipper to make the user to be able to slide between layouts by clicking to related button, But the thing is, I have around 10 different layouts and some of them are quite complex. So I get "Out of Memory" Error.

I searched something on the internet and what I see is ,swiping between layouts with gestures. And What I want is just to be able to slide between two layouts with "slide in" and "slide out" animations. NOT with GESTURES and SWIPING, by just clicking the button. It will be like a new activity starts but I just want to slide between layouts. Thanks is advance !

osayilgan
  • 5,873
  • 7
  • 47
  • 68

2 Answers2

2

Fragments! Dynamically build, show, hide and destroy them. And use XML animations to do whatever animation you want for transition.

Budius
  • 39,391
  • 16
  • 102
  • 144
1

Use the ViewPager with Fragments, both of which can be found in the support library and are compatible all the way down to Android 1.6.

Michell Bak
  • 13,182
  • 11
  • 64
  • 121
  • I need to let the user slide between layouts or fragments by clicking to the button, not swiping with the finger, as like new activity starts. Any idea ? – osayilgan Aug 15 '12 at 12:31
  • You can actually use the same thing. Check out the ViewPager API's - there are calls to set the active item. – Michell Bak Aug 15 '12 at 12:39
  • @OKSayi as a follow up question: Why don't you want to let the users slide it? It's part of the Android design guidelines and usually gives a very nice fluid presentation. – Budius Aug 15 '12 at 13:09
  • @Budius According to my application, it's not a swiping screen. Imagine that I have a list view as a main container and If the user clicks on the first item it goes "to news page" let's say. And if the second button is clicked it will go to "gallery page", and so on. And these all need to be in the same activity and they need to be sliding with animation as like in view flipper with "slide in" and "slide out" animation. I guess couldn't explain my situation well. Did you understand what I mean ? – osayilgan Aug 15 '12 at 13:17
  • That's really a poor way of designing an application. There's a reason why this kind of stuff isn't easy to do... – Michell Bak Aug 15 '12 at 13:53
  • @MichellBak ViewPager is working after disabled the swiping. But it doesn't look like the right way, because I need to handle all of the click events in the PagerAdapter. Any idea ? for better way ? – osayilgan Aug 15 '12 at 14:13
  • @OKSayi Now that you better explained what your app will be doing I can said for sure: Use fragments (as I said on my answer) and XML animations to perform whatever animation you want. Remember that in a FragmentTransaction you should `.setAnimation()` **before** adding, removing or replacing any fragment. Another way of doing if you're 100% sure you will never use this app on tablets is to create an Activity for each view and animate the transitions accordingly. – Budius Aug 15 '12 at 14:28
  • @Budius I dont have any concerns about using this app in tablets because it is just for android phones, but the way you are saying about activities doesn't seem a good idea ,because this page that I'm trying to create is the first tab of whole application, so I need to stay in the same tab in this manner. I will try the fragment way and let you know if it works. Thanks for the answer. – osayilgan Aug 15 '12 at 14:35
  • The tabs is another bit of the puzzle you haven't mentioned before. If I knew I would just say go with fragments. – Budius Aug 15 '12 at 14:37
  • @Budius thanks for the answer, I tried the fragments way and it works, I will keep going in this way in my application. – osayilgan Aug 16 '12 at 07:06