6

I'm building and Android app that needs to go through steps like a wizard.

Current structure:

At the moment I'm using one activity with separate views.xml for each step, then I'm using setContentView(activeStep) to display the active step.

I ran into some difficulties when trying to animate between the steps. I used the following code:

LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(activeStep, null, false);
view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.slide_in));
setContentView(view);

The result: the first view was gone and the new one animated, not a smooth transition.

My goal is to animate both views, one slides out the other in.

Question: Is it possible to do it with my current structure (reminder: one activity, many views) or should I treat each step as a separate activity?

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186
  • 1
    Have you thought about using ViewSwitcher instead? http://www.youtube.com/watch?v=mGwG8-chUEM to see it and http://www.ctctlabs.com/index.php/blog/detail/android_dont_overlook_viewswitcher/ for help – TryTryAgain Jan 09 '12 at 16:49
  • Thanks for the reply, I will try and let you know – Shlomi Schwartz Jan 10 '12 at 07:52

2 Answers2

3

I guess there is more the one way of implementing step progress with animation, here is how I did it:

private static ViewAnimator viewAnimator;

 public void onCreate(Bundle savedInstanceState) {
        viewAnimator = new ViewAnimator(this);
        View step1 = View.inflate(activity, R.layout.step_1, null);
        View step2 = View.inflate(activity, R.layout.step_2, null);
        View step3 = View.inflate(activity, R.layout.step_3, null);
        viewAnimator.addView(step1);
        viewAnimator.addView(step2);
        viewAnimator.addView(step3);
        viewAnimator.setInAnimation(activity, R.anim.slide_in);
        viewAnimator.setOutAnimation(activity, R.anim.slide_out);
        setContentView(viewAnimator);
    }

then clicking a button I call viewAnimator.showNext() and viewAnimator.showPrevious() ViewSwitcher was not good for my purpose, because it can hold only 2 views at a time

Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186
0

It would probably be best to use one Activity and a few different View structures if each step in the process is related.

You probably shouldn't use setContentView to change views with each step. Instead, possibly hide or unhide each item, or move it off the screen.

Cody
  • 8,686
  • 18
  • 71
  • 126