-1

I'm working on an application and let's say I have 5 different layouts plus a main layout which has links to each layout. In the main layout when the user click to the first button it is suppose to go the related layout by sliding. And It's same for other views.

When the user goes to one of these layouts, the next layout also has a couple of links to other layouts as like a chain. And this chain is moving from layout to the other one by sliding.

I have tried to do this with view flipper but since I have so many different layouts and they have background images and some contents in it, I get out of memory error.

So I'm trying to find a solution in this manner. Any idea how to accomplish this ?

osayilgan
  • 5,873
  • 7
  • 47
  • 68

2 Answers2

1

I would recommend you to use Jake Whartons ViewPageIndicator:

Create a Fragment for every of your Layouts and set the layout to your Fragment with the onCreateView() methode inside your fragment:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {

        return inflater.inflate(R.layout.layout, container, false);
    }

Now create a FragmentPagerAdapter there sould be a methode called getItem(). Switch the Position and set it to your Fragment:

 public Fragment getItem(int position) {
 switch(position)
       {
               case 0:
                    TestFragment fragment = new TestFragment();  
                    return fragment;

                case 1:
                    TestFragment2 fragment2 = new TestFragment2();  
                    return fragment2;

         }

                    DefaultFragment fragment3 = new DefaultFragment();  
                    return fragment3;

         }

Now you should be able to swipe to your Layouts(Fragments) easily

Ahmad
  • 69,608
  • 17
  • 111
  • 137
0

Start a new android.app.Activity hosting each layout and override the transitions between activities using overridePendingTransition(R.anim.animation_leave, R.anim.animation_enter); where *.anim.animation_leave and _enter are neatly already spec'ed out for you in this SO answer.

You can write the overridePendingTransition code immediately after your call to start the 'chained' activity and (if required) the reverse effect can be applied by providing the opposing transitions after calling finish() on the Activity or selecting the 'Up' navigation button press or 'back-button' press.

Having a single activity manage one layout will (in my experience) also benefit code maintainability.

Community
  • 1
  • 1
BrantApps
  • 6,362
  • 2
  • 27
  • 60
  • This page that I want to design will be one of the tabs. so If start a new activity, it will make the things more complicated. thanks for suggestion. – osayilgan Aug 14 '12 at 15:19
  • I see... Sorry, didn't realise this was under the context of a tab. Re: the ````ViewPager```` suggestions with that in mind - having a view pager under a tab sounds bad. It's essentially two forms of lateral navigation that may confuse the user as they expect to swipe between tabs but are met with "view 2" from the first tab? This section of the Developer Guide is great, read it: http://developer.android.com/training/design-navigation/descendant-lateral.html – BrantApps Aug 14 '12 at 15:27
  • Let's say I have basically 5 tabs, and the first tab has a list of some information and when the user clicks on one of these list items it is suppose to slide to next layout but every single thing happens in this manner will be still staying in the first tab. The rest of the tabs are containing something else. So I'm actually trying to find a way for paging. As I said I tried view flipper but since it holds all the children in memory, I get out of memory issue. I can still just change the content view when user clicks an item in the list and set it. – osayilgan Aug 14 '12 at 16:06
  • but I want to make it with "slide in" and "slide out" animations as we are able to do it in view flipper. – osayilgan Aug 14 '12 at 16:07
  • Yea, I get you. I don't have the answer without giving a perhaps not great, "use another design paradigm" suggestion! I haven't seen this paradigm being used elsewhere and since I am no navigational/UI guru this would flag to me that I'm doing something the user might not get/the framework doesn't accommodate. Draw a few Screen Maps of what you need to happen and see if something more standard comes out in the wash... http://developer.android.com/training/design-navigation/wireframing.html – BrantApps Aug 15 '12 at 19:51
  • I found the way, I tried something with fragments and it worked in the way I want. No need to use activities. – osayilgan Aug 16 '12 at 07:13